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