#include <bits/stdc++.h>
using namespace std;
const long long N = 1234567;
const long long mod = 1e9 + 7;
long long n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(10);
  int t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b >> n;
    if (n % 3 == 0) {
      cout << a << endl;
    } else if (n % 3 == 1) {
      cout << b << endl;
    } else {
      cout << (a ^ b) << endl;
    }
  }
  return 0;
}
