#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t, a, b, n;
  cin >> t;
  while (t--) {
    cin >> a >> b >> n;
    long long int x = 0;
    x = a xor b;
    if (n % 3 == 0) cout << a << endl;
    if (n % 3 == 1) cout << b << endl;
    if (n % 3 == 2) cout << x << endl;
  }
}
