#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long i, j = 0, r = 200, p, q, k = 1, ans = 0, d, y = 0, x, n, h,
               flag = 0, m = 0, id, c, h1, h2, a1, b1, w, a, b;
  cin >> p >> q >> n;
  if (n % 3 == 0)
    cout << p << endl;
  else if (n % 3 == 1)
    cout << q << endl;
  else
    cout << (p ^ q) << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
