#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long x, y, index;
    cin >> x >> y >> index;
    long long ans = x ^ y;
    if (index % 3 == 0)
      cout << x << endl;
    else if (index % 3 == 1)
      cout << y << endl;
    else
      cout << ans << endl;
  }
}
