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