#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1000;
const long long INF64 = 1e18 + 1000;
const int N = 6 * 100 * 1000 + 100;
const int MOD = 1e9 + 9;
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
void spr(int x) { cout << setprecision(x) << fixed; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int a, b, n;
    cin >> a >> b >> n;
    if (n % 3 == 0)
      cout << a << endl;
    else if (n % 3 == 1)
      cout << b << endl;
    else
      cout << (a ^ b) << endl;
  }
}
