#include <bits/stdc++.h>
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int a, b, n;
    scanf("%d%d%d", &a, &b, &n);
    int x = n % 3, ans;
    if (x == 0)
      ans = a;
    else if (x == 1)
      ans = b;
    else
      ans = a ^ b;
    printf("%d\n", ans);
  }
  return 0;
}
