#include <bits/stdc++.h>
using namespace std;
long long int i, j, count, k, t, l, n, a, b, sum1, sum2, max1, max2;
string s1, s2;
int main() {
  cin >> t;
  while (t--) {
    cin >> a >> b >> n;
    n = n % 3;
    if (n == 0) {
      cout << a << endl;
    } else if (n == 1) {
      cout << b << endl;
    } else {
      cout << (a ^ b) << endl;
    }
  }
}
