#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long int a, b, c, t, i, e;
  vector<long long int> d(10000);
  cin >> t;
  while (t--) {
    e = 0;
    cin >> a >> b >> c;
    d[1] = b;
    if (c % 3 == 0)
      e = a;
    else if (c % 3 == 1)
      e = b;
    else
      e = (a ^ b);
    cout << e << endl;
  }
}
