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