#include <bits/stdc++.h>
using namespace std;
const unsigned long long hash1 = 201326611;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long _INF = 0xc0c0c0c0c0c0c0c0;
const long long mod = (int)1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long ksm(long long a, long long b, long long mod) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
inline int read() {
  int date = 0, m = 1;
  char ch = 0;
  while (ch != '-' && (ch<'0' | ch> '9')) ch = getchar();
  if (ch == '-') {
    m = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    date = date * 10 + ch - '0';
    ch = getchar();
  }
  return date * m;
}
int main() {
  int t;
  long long a, b, n;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld%lld", &a, &b, &n);
    if (n % 3 == 0) {
      printf("%lld\n", a);
    } else if (n % 3 == 1) {
      printf("%lld\n", b);
    } else {
      printf("%lld\n", a ^ b);
    }
  }
  return 0;
}
