#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long 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;
}
int main() {
  int t, i = 1;
  cin >> t;
  while (t--) {
    solve();
    ++i;
  }
  return 0;
}
