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