#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 6;
int a[4], n;
int main() {
  int T;
  cin >> T;
  while (T--) {
    cin >> a[0] >> a[1] >> n;
    a[2] = a[0] ^ a[1];
    cout << a[n % 3] << endl;
  }
  return 0;
}
