#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int main() {
  srand(1373737);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long a, b, n;
    cin >> a >> b >> n;
    if (n % 3ll == 0ll) cout << a << '\n';
    if (n % 3ll == 1ll) cout << b << '\n';
    if (n % 3ll == 2ll) cout << (a ^ b) << '\n';
  }
  return 0;
}
