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