#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, a, b, n, x, i;
  cin >> t;
  for (i = 1; i <= t; i++) {
    cin >> a >> b >> n;
    if (n == 0 || n % 3 == 0) {
      cout << a << endl;
      continue;
    }
    if (n == 1 || n % 3 == 1) {
      cout << b << endl;
      continue;
    }
    x = a ^ b;
    { cout << x << endl; }
  }
}
