#include <bits/stdc++.h>
using namespace std;
int t, a, b, n;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int main() {
  t = read();
  while (t > 0) {
    --t;
    a = read();
    b = read();
    n = read();
    n %= 3;
    if (n == 0)
      printf("%d", a);
    else if (n == 1)
      printf("%d", b);
    else
      printf("%d", a ^ b);
    printf("\n");
  }
  return 0;
}
