#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ina(a) for(auto &i: a) cin>>i
#define opa(a) for(auto &i: a) cout << i << ' '; cout << endl;
#define swap(a, i, j) { auto temp = a[i]; a[i] = a[j]; a[j] = temp; }
#define v vector
#define p(res) cout << res << '\n'
int f(v<v<int>> &dp, int mid, int l){
int res=0;
for(int b=0; b<32; b++){
int left=(l>0)?dp[b][l-1]:0;
if (dp[b][mid]-left == l-mid+1) res|=(1<<b);
}
return res;
}
// Code Here!
void solve(){
int n, q; cin>>n>>q;
v<int> a(n);
ina(a);
int res=0;
v<v<int>> dp(32, v<int> (n, 0));
for(int i=0; i<n; i++){
for(int b=0; b<32; b++){
if (a[i]&(1<<b)) dp[b][i]++;
}
}
for(int b=0; b<32; b++){
for(int i=1; i<n; i++){
dp[b][i]+=dp[b][i-1];
}
}
for(int qq=0; qq<q; qq++){
int k, l; cin>>k>>l; l--;
int i=l, j=n, cur=n+1;
while(i<=j){
int mid=i+(j-i)/2;
if (f(dp, mid, l) >= k) {
cur=mid; i=mid+1;
}
else j=mid-1;
}
if (cur!=n+1) cur++;
res^=cur;
}
p(res);
}
int main(){
int t=1;
cin>>t;
while(t--){
solve();
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKI2RlZmluZSBpbmEoYSkgZm9yKGF1dG8gJmk6IGEpIGNpbj4+aQojZGVmaW5lIG9wYShhKSBmb3IoYXV0byAmaTogYSkgY291dCA8PCBpIDw8ICcgJzsgY291dCA8PCBlbmRsOwojZGVmaW5lIHN3YXAoYSwgaSwgaikgeyBhdXRvIHRlbXAgPSBhW2ldOyBhW2ldID0gYVtqXTsgYVtqXSA9IHRlbXA7IH0KI2RlZmluZSB2IHZlY3RvcgojZGVmaW5lIHAocmVzKSBjb3V0IDw8IHJlcyA8PCAnXG4nCgppbnQgZih2PHY8aW50Pj4gJmRwLCBpbnQgbWlkLCBpbnQgbCl7CiAgICBpbnQgcmVzPTA7CiAgICBmb3IoaW50IGI9MDsgYjwzMjsgYisrKXsKICAgICAgICBpbnQgbGVmdD0obD4wKT9kcFtiXVtsLTFdOjA7CiAgICAgICAgaWYgKGRwW2JdW21pZF0tbGVmdCA9PSBsLW1pZCsxKSByZXN8PSgxPDxiKTsKICAgIH0KICAgIHJldHVybiByZXM7Cn0KCi8vIENvZGUgSGVyZSEKdm9pZCBzb2x2ZSgpewogICAgaW50IG4sIHE7IGNpbj4+bj4+cTsKICAgIHY8aW50PiBhKG4pOyAKICAgIGluYShhKTsKICAgIGludCByZXM9MDsKICAgIHY8djxpbnQ+PiBkcCgzMiwgdjxpbnQ+IChuLCAwKSk7CiAgICBmb3IoaW50IGk9MDsgaTxuOyBpKyspewogICAgICAgIGZvcihpbnQgYj0wOyBiPDMyOyBiKyspewogICAgICAgICAgICBpZiAoYVtpXSYoMTw8YikpIGRwW2JdW2ldKys7CiAgICAgICAgfQogICAgfQogICAgZm9yKGludCBiPTA7IGI8MzI7IGIrKyl7CiAgICAgICAgZm9yKGludCBpPTE7IGk8bjsgaSsrKXsKICAgICAgICAgICAgZHBbYl1baV0rPWRwW2JdW2ktMV07CiAgICAgICAgfQogICAgfQogICAgZm9yKGludCBxcT0wOyBxcTxxOyBxcSsrKXsKICAgICAgICBpbnQgaywgbDsgY2luPj5rPj5sOyBsLS07CiAgICAgICAgaW50IGk9bCwgaj1uLCBjdXI9bisxOyAKICAgICAgICB3aGlsZShpPD1qKXsKICAgICAgICAgICAgaW50IG1pZD1pKyhqLWkpLzI7CiAgICAgICAgICAgIGlmIChmKGRwLCBtaWQsIGwpID49IGspIHsKICAgICAgICAgICAgICAgIGN1cj1taWQ7IGk9bWlkKzE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBqPW1pZC0xOwogICAgICAgIH0KICAgICAgICBpZiAoY3VyIT1uKzEpIGN1cisrOwogICAgICAgIHJlc149Y3VyOwogICAgfQogICAgcChyZXMpOwp9CgppbnQgbWFpbigpewogICAgaW50IHQ9MTsKICAgIGNpbj4+dDsKICAgIHdoaWxlKHQtLSl7CiAgICAgICAgc29sdmUoKTsKICAgIH0KfQ==