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