#include <bits/stdc++.h>
using namespace std;
long long a, b, c, t, V[3];
int main() {
  cin >> t;
  while (t--) {
    cin >> a >> b >> c;
    V[0] = a;
    V[1] = b;
    V[2] = a ^ b;
    cout << V[c % 3] << '\n';
  }
  return 0;
}
