#include <bits/stdc++.h>
using namespace std;
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}
struct debug {
  template <class T>
  debug& operator<<(const T&) {
    return *this;
  }
};
using ll = long long;
template <typename T>
void min_self(T& a, T b) {
  a = min(a, b);
}
template <typename T>
void max_self(T& a, T b) {
  a = max(a, b);
}
void test_case() {
  int a, b, n;
  cin >> a >> b >> n;
  if (n % 3 == 0) {
    cout << a << "\n";
  } else if (n % 3 == 1) {
    cout << b << "\n";
  } else
    cout << (a ^ b) << "\n";
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    test_case();
  }
}
