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