#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e9;
const long long inf = (long long)1e18;
const long double eps = (long double)1e-6;
const long long mod = (long long)1e9 + 7;
const long long MAXN = 1001;
const long long MAXLOG = 19;
const long long maxlen = (long long)1e5;
const long long asci = (long long)256;
const long long block = 707;
template <class T>
istream &operator>>(istream &in, vector<T> &arr) {
  for (T &cnt : arr) {
    in >> cnt;
  }
  return in;
};
void solve() {
  long long n, a, b;
  cin >> a >> b >> n;
  if (n % 3 == 0) cout << a;
  if (n % 3 == 1) cout << b;
  if (n % 3 == 2) cout << (a ^ b);
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
