#include <bits/stdc++.h>
using namespace std;
bool test = 1;
void solve() {
  int n, a, b;
  cin >> a >> b >> n;
  if (n % 3 == 0) {
    cout << a << endl;
  } else if (n % 3 == 1) {
    cout << b << endl;
  } else {
    int tmp = a ^ b;
    cout << tmp << endl;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  if (test) {
    int t;
    cin >> t;
    while (t--) solve();
  } else
    solve();
  return 0;
}
