#include <bits/stdc++.h>
using namespace std;
int t, a, b, n;
int main() {
  cin >> t;
  while (t--) {
    cin >> a >> b >> n;
    switch (n % 3) {
      case 0:
        cout << a;
        break;
      case 1:
        cout << b;
        break;
      default:
        cout << (a ^ b);
        break;
    }
    cout << '\n';
  }
}
