#include <bits/stdc++.h>
using namespace std;
inline void fileio(const char* in, const char* out) {
  freopen(in, "r", stdin);
  freopen(out, "w", stdout);
}
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<ll> VL;
const char nl = '\n';
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const ld EPS = 1e-9, PI = acos(-1);
void deal(int T) {
  int a, b, n;
  cin >> a >> b >> n;
  int ans;
  switch (n % 3) {
    case 0:
      ans = a;
      break;
    case 1:
      ans = b;
      break;
    case 2:
      ans = a ^ b;
      break;
  }
  cout << ans << nl;
}
int main() {
  atexit([]() { cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  for (int i = 0; i < (T); ++i) deal(i);
  return 0;
}
