#include <bits/stdc++.h>
using namespace std;
const long int N = 2e6 + 200;
long int arr[N], ans[N];
set<pair<long int, long int>> s1, s2;
map<long int, long int> mp;
pair<long int, long int> p;
int main() {
  long int t;
  cin >> t;
  while (t--) {
    long int n, a, b;
    cin >> a >> b >> n;
    if (n % 3 == 0)
      cout << a;
    else if (n % 3 == 1)
      cout << b;
    else
      cout << (long int)(a ^ b);
    cout << endl;
  }
  return 0;
}
