#include <bits/stdc++.h>
using namespace std;
template <typename dataType>
dataType nthGrayCode(dataType n) {
  return (n ^ (n >> 1));
}
template <typename dataType>
void generateAllSubset(vector<dataType> &data) {
  int i, j, n;
  n = data.size();
  for (i = 0; i < (1 << n); i++) {
    for (j = 0; j < n; j++) {
      if (i & (1 << j)) {
        cout << data[j] << " ";
      }
    }
    cout << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test, a, b, n, r, ans;
  cin >> test;
  while (test--) {
    cin >> a >> b >> n;
    r = n % 3;
    if (r == 0)
      ans = a;
    else if (r == 1)
      ans = b;
    else
      ans = a ^ b;
    cout << ans << "\n";
  }
  return 0;
}
