#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, c, d, i, j, k;
  long long t;
  cin >> t;
  while (t--) {
    cin >> a >> b >> c;
    if (c % 3 == 0) {
      cout << a << endl;
    } else if (c % 3 == 1) {
      cout << b << endl;
    } else {
      cout << (a ^ b) << endl;
    }
  }
  return 0;
}
