#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int a, b, c;
    cin >> a >> b >> c;
    if (c % 3 == 0) {
      cout << a << '\n';
      continue;
    }
    if (c % 3 == 1)
      cout << b << '\n';
    else
      cout << (a ^ b) << '\n';
  }
  return 0;
}
