#include <bits/stdc++.h>
using namespace std;
long long N = 500005;
long long MAX = 9223372036854775807;
long long MOD = 1000000007;
long double PI = 4 * atan(1);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout.precision(30);
  long long n, m, k, a, b, c, x, y;
  int t;
  cin >> t;
  while (t--) {
    cin >> a >> b >> n;
    if (n % 3 == 0)
      cout << a << "\n";
    else if (n % 3 == 1)
      cout << b << "\n";
    else
      cout << (a ^ b) << "\n";
  }
  return 0;
}
