#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
int t, a, b, c, n;
int main() {
  cin >> t;
  while (t--) {
    cin >> a >> b >> n;
    c = a ^ b;
    if ((n + 1) % 3 == 1)
      cout << a << endl;
    else if ((n + 1) % 3 == 2)
      cout << b << endl;
    else
      cout << c << endl;
  }
  return 0;
}
