#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, n;
    cin >> a >> b >> n;
    if (n == 0)
      cout << a << endl;
    else if (n == 1)
      cout << b << endl;
    else {
      long long num = (a ^ b);
      long long rem = n % 3;
      if (rem == 0)
        cout << a << endl;
      else if (rem == 1)
        cout << b << endl;
      else if (rem == 2)
        cout << num << endl;
    }
  }
  return 0;
}
