#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int a, b, n;
    cin >> a >> b >> n;
    switch (n % 3) {
      case 0:
        cout << a << '\n';
        break;
      case 1:
        cout << b << '\n';
        break;
      case 2:
        cout << (a ^ b) << '\n';
        break;
    }
  }
  return 0;
}
