#include <bits/stdc++.h>
using namespace std;
long long gcd() { return 0ll; }
template <typename T, typename... Args>
T gcd(T a, Args... args) {
  return __gcd(a, (__typeof(a))gcd(args...));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T, i, j;
  cin >> T;
  while (T--) {
    long long a, b, n;
    cin >> a >> b >> n;
    if (n % 3 == 0)
      cout << a << "\n";
    else if (n % 3 == 1)
      cout << b << "\n";
    else
      cout << (a ^ b) << "\n";
  }
  return 0;
}
