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