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