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