#include <bits/stdc++.h>
using namespace std;
double const EPS = 1e-8, PI = acos(-1);
const int N = 2e3 + 9, M = 1e6 + 19, OO = 1e9 + 9;
int main() {
  cout << fixed << setprecision(0), ios::sync_with_stdio(false),
      cin.tie(nullptr), cout.tie(nullptr);
  ;
  long long a, b, n;
  int t;
  cin >> t;
  while (t--) {
    cin >> a >> b >> n;
    long long arr[3];
    arr[0] = a, arr[1] = b, arr[2] = (a ^ b);
    cout << arr[n % 3] << '\n';
  }
  return 0;
}
