#include <bits/stdc++.h>
using namespace std;
ifstream fin (“ghicitoare.in”);
ofstream fout (“ghicitoare.out”);
#define cin fin
#define cout fout
int n, x, T, k;
int xor_n (int n)
{
switch(n % 4){
case 0:
return n;
break;
case 1:
return 1;
break;
case 2:
return n + 1;
break;
case 3:
return 0;
break;
}
}
int main()
{
cin >> T;
while(T—){
cin >> n >> k;
x = xor_n(n);
x ^= k;
cout << x << “\n”;
}
return 0;
}