#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll M = 1000000007;
const ll N = 998244353;
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll inv(ll x, ll m) { return power(x, m - 2, m); }
struct comp {
  template <typename T>
  bool operator()(const T &a, const T &b) {
    if (a.first == b.first)
      return (a.second < b.second);
    else
      return (a.first < b.first);
  }
};
bool mod(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  if (a.first != b.first)
    return (a.first > b.first);
  else
    return (a.second > b.second);
}
vector<bool> pr(1000000 + 1, 1);
void sieve(ll mn, ll mx) {
  for (ll i = mn; i * i <= mx; i++)
    if (pr[i - mn] == 1)
      for (ll j = i * i; j <= mx; j += i) pr[j - mn] = 0;
}
bool isValid(ll i, ll j, ll t1, ll n, ll t2, ll m) {
  if (i >= t1 && i < n && j >= t2 && j < m) {
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m, i, j, k, num, num1, num2, flag = 0;
  int t;
  cin >> t;
  while (t--) {
    ll n, m, i, j, k, num, num1, num2, flag = 0;
    ll a, b;
    cin >> a >> b >> n;
    ll c = a ^ b;
    vector<ll> v = {a, b, c};
    cout << v[n % 3] << "\n";
  }
  return 0;
}
