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