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