#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, j;
  cin >> t;
  for (j = 0; j <= t - 1; j++) {
    int a, b, c, n;
    cin >> a >> b >> n;
    n = n % 3;
    c = a ^ b;
    if (n == 0) {
      cout << a << endl;
    } else if (n == 1) {
      cout << b << endl;
    } else {
      cout << c << endl;
    }
  }
}
