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