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