#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  int test;
  cin >> test;
  while (test--) {
    int a, b, n;
    cin >> a >> b >> n;
    int c = a ^ b;
    vector<int> d = {a, b, c};
    cout << d[n % 3] << '\n';
  }
  return 0;
}
