#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long test = 1;
  cin >> test;
  while (test--) {
    long long a[3], n;
    cin >> a[0] >> a[1] >> n;
    a[2] = a[0] ^ a[1];
    long long x = n % 3;
    cout << a[x] << endl;
  }
  return 0;
}
