#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int a, b, n;
    scanf("%d %d %d", &a, &b, &n);
    if (n % 3 == 0) {
      printf("%d\n", a);
    }
    if (n % 3 == 1) {
      printf("%d\n", b);
    }
    if (n % 3 == 2) {
      printf("%d\n", a ^ b);
    }
  }
}
