#include <bits/stdc++.h>
using namespace std;
int test, a[3], n;
int main() {
  cin >> test;
  while (test--) {
    cin >> a[0] >> a[1] >> n;
    a[2] = a[0] ^ a[1];
    cout << a[n % 3] << endl;
  }
}
