#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a, b, c;
  vector<int> ans;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b >> c;
    ans.clear();
    ans.push_back(a);
    ans.push_back(b);
    int x = 0, y = 1, t = 1;
    if (a == 0) {
      if (c % 3 == 0) {
        cout << a << endl;
      } else {
        cout << b << endl;
      }
    } else if (b == 0) {
      if (c % 3 == 1) {
        cout << b << endl;
      } else {
        cout << a << endl;
      }
    } else {
      while (t == 1) {
        int g = ans[x] ^ ans[y];
        if (g == ans[0]) {
          t = 0;
        } else {
          ans.push_back(g);
        }
        ++x;
        ++y;
      }
      cout << ans[c % (int)(ans.size())] << endl;
    }
  }
  return 0;
}
