#include using namespace std; #define ll long long #define all(x) x.begin(),x.end() #define rep(i,a,b) for(int i=a;i<=b;i++) #define rep_r(i,a,b) for(int i=a;i>=b;i--) #define each(a,x) for (auto& x : a) using pi = pair; using pl = pair; using vi = vector; using vl = vector; #define sz(x) int(x.size()) #define so(x) sort(all(x)) #define so_r(x) sort(all(x),greater()) #define lb lower_bound #define ub upper_bound const char nl = '\n'; int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; int bit_cnt(int x){ return __builtin_popcount(x); } ll bex(ll a, ll b, ll mod = 1e9 + 7){ll res = 1LL; while(b){ if (b&1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;} template bool chmax(t&a,u b){if(a bool chmin(t&a,u b){if(b ans = 2 * L = (L << 1) // case L + 1 == R => ans = (2L) ^ (2L + 1) = 1 // case L + 2 == R => ans = (2L) ^ (2L + 1) ^ (2L + 2) ^ (2L + 2) = 1 // case L + 3 == R => ans = (2L) ^ (2L+1) ^ (2L+2) ^ (2L+3) // ^ (2L+2) ^ (2L+3) = 1 // case L + 4 == R => ans = (2L) ^ (2L+1) ^ (2l+2) ^ (2L+3) ^ (2L+4) // ^ (2L+2) ^ (2L+3) ^ (2L+4) // ^ (2L+4) = 1 ^ (2L + 4) = 2L + 5 // 5 -> 3 -> 1 = 0 ^ 1 ^ (2L+4) // case L + 5 == R => ans = 6 -> 4 -> 2 = 0 // case L + 6 == R => ans = 7 -> 5 -> 3 -> 1 = 0 // case L + 7 == R => ans = 8 -> 6 -> 4 -> 2 = 0 // 10 -> 8 -> 6 -> 4 -> 2 = // 9 -> 7 -> 5 -> 3 -> 1 = 2L + 8 (diff == 9) // 11 -> 9 -> 7 -> 5 -> 3 -> 1 = 1 ^ 1 ^ 1 = 1 (diff == 11) // 13 -> 11 -> 9 -> 7 -> 5 -> 3 -> 1 = 1 ^ 1 ^ 1 // diff = R - L + 1 // if diff % 8 == 1,3,5,7 // = 1 => L + R // = 3 => 1 // = 5 => L + R + 1 // = 7 => 0 void solve(){ int T; cin >> T; while(T--){ ll L,R; cin >> L >> R; ll diff = R - L + 1; ll r = diff % 8; if (r == 1) cout << L + R << nl; else if (r == 2) cout << 1 << nl; // 1 else if (r == 3) cout << 1 << nl; else if (r == 4) cout << 1 << nl; // 3 -> 1 else if (r == 5) cout << L + R + 1 << nl; // in this case: 1 ^ (L + R) = L + R + 1 (because l + r % 2 == 0) else if (r == 7) cout << 0 << nl; // example L + 6 == R => 7 -> 5 -> 3 -> 1 => 1 ^ 1 = 0 (if we add more 8 to R then we still have (1 ^ 1) = 0 ^ old = old) else if (r == 0) cout << 0 << nl; } } ll calc(ll l, ll r){ ll ans = 0; rep(i,l,r){ rep(j,i,r){ if (i+j<=l+r) { ans ^= (i + j); } } } return ans; } void test() { rep(i,4,3+11) { cout << calc(3,i) << nl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; // test(); while (t--){ solve(); } }