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