#include <bits/stdc++.h>
int main(int argc, char **argv) {
  int n, a, b, m, c;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a >> b >> m;
    c = a ^ b;
    if (m % 3 == 0)
      std::cout << a << "\n";
    else if (m % 3 == 1)
      std::cout << b << "\n";
    else
      std::cout << c << "\n";
  }
  getchar();
  return (0);
}
