#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * w;
}
int main() {
  int T = read();
  while (T--) {
    int a = read();
    int b = read();
    int n = read() % 3;
    if (n == 0)
      cout << a << endl;
    else if (n == 1)
      cout << b << endl;
    else if (n == 2)
      cout << (a ^ b) << endl;
  }
  return 0;
}
