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