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