#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long sum(long long a, long long b, long long mod) {
  long long ans = a + b;
  if (ans > mod) ans -= mod;
  return ans;
}
long long mul(long long a, long long b, long long mod) { return (a * b) % mod; }
long long dif(long long a, long long b, long long mod) {
  long long res = a - b;
  if (res < 0) res += mod;
  return res;
}
long long binpow(long long a, long long b, long long mod) {
  if (b == 1) return a;
  if (b % 2 == 0) {
    long long bb = binpow(a, b / 2, mod);
    return mul(bb, bb, mod);
  }
  if (b % 2 == 1) {
    long long bb = binpow(a, b / 2, mod);
    bb = mul(bb, bb, mod);
    return mul(bb, a, mod);
  }
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &V) {
  for (int i = 0; i < (int)V.size(); ++i) {
    if (i != 0) os << ' ';
    os << V[i];
  }
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &V) {
  for (int i = 0; i < (int)V.size(); ++i) {
    is >> V[i];
  }
  return is;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int a, b, n;
    cin >> a >> b >> n;
    if (n % 3 == 0) {
      cout << a;
    } else if (n % 3 == 1) {
      cout << b;
    } else {
      cout << (a ^ b);
    }
    cout << "\n";
  }
  return 0;
}
