#include <bits/stdc++.h>
using namespace std;
int main() {
  int T, a, b, n, k, ans;
  cin >> T;
  for (int i = 0; i < T; i++) {
    cin >> a >> b >> n;
    k = n % 3;
    if (k == 0)
      ans = a;
    else if (k == 1)
      ans = b;
    else
      ans = a ^ b;
    cout << ans << endl;
  }
  return 0;
}
