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