#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int test, n, m, i, j, k, l, o;
  cin >> test;
  while (test--) {
    cin >> n >> l >> m;
    m = m % 3;
    if (m == 0) {
      cout << n << "\n";
    } else if (m == 1) {
      cout << l << "\n";
    } else {
      cout << (n ^ l) << "\n";
    }
  }
  return 0;
}
