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