#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
long long f[N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, b, n;
    cin >> a >> b >> n;
    f[0] = a, f[1] = b;
    for (int i = 2; i <= 4; i++) f[i] = f[i - 1] ^ f[i - 2];
    cout << f[n % 3] << endl;
  }
  return 0;
}
