#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b, y;
    cin >> a >> b >> y;
    long long int x = y % 3LL;
    if (x == 0) {
      cout << a << endl;
    } else if (x == 1)
      cout << b << endl;
    else
      cout << (a xor b) << endl;
  }
  return 0;
}
