#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
long long fix_mod(long long x, long long y) { return (y + x % y) % y; }
void fast() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
int main() {
  fast();
  int t;
  long long a, b, n;
  cin >> t;
  while (t--) {
    cin >> a >> b >> n;
    if (n % 3 == 0)
      cout << a << "\n";
    else if (n % 3 == 1)
      cout << b << "\n";
    else
      cout << (a ^ b) << "\n";
  }
}
