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