Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:   $f(0) = a$;  $f(1) = b$;  $f(n) = f(n-1) \oplus f(n-2)$ when $n > 1$, where $\oplus$ denotes the bitwise XOR operation. 

You are given three integers $a$, $b$, and $n$, calculate $f(n)$.

You have to answer for $T$ independent test cases.


-----Input-----

The input contains one or more independent test cases.

The first line of input contains a single integer $T$ ($1 \le T \le 10^3$), the number of test cases.

Each of the $T$ following lines contains three space-separated integers $a$, $b$, and $n$ ($0 \le a, b, n \le 10^9$) respectively.


-----Output-----

For each test case, output $f(n)$.


-----Example-----
Input
3
3 4 2
4 5 0
325 265 1231232

Output
7
4
76



-----Note-----

In the first example, $f(2) = f(0) \oplus f(1) = 3 \oplus 4 = 7$.

Difficulty: EASY

Solutions:
number = int(input())
for i in range(number):
	(a, b, n) = map(int, input().split())
	xorinacci = [a, b, a ^ b]
	if n == 0:
		print(xorinacci[0])
	elif n == 1:
		print(xorinacci[1])
	else:
		print(xorinacci[n % 3])


testCase = int(input())
for x in range(0, testCase):
	(a, b, n) = map(int, input().split())
	m = n % 3
	if m == 0:
		print(a)
	elif m == 1:
		print(b)
	else:
		print(a ^ b)


t = int(input())
store = []
for i in range(t):
	a = 0
	b = 0
	n = 0
	c = 0
	(a, b, n) = input().split()
	a = int(a)
	b = int(b)
	n = int(n)
	ans = 0
	c = n % 3
	if c == 0:
		ans = a
	if c == 1:
		ans = b
	if c == 2:
		ans = a ^ b
	store.append(ans)
for i in store:
	print(i, sep='\n')


T = int(input())

def nthXorFib(n, a, b):
	if n == 0:
		print(a)
		return
	if n == 1:
		print(b)
		return
	if n == 2:
		print(a ^ b)
		return
	return nthXorFib(n % 3, a, b)
for i in range(T):
	(a, b, n) = map(int, input().split())
	nthXorFib(n, a, b)


R = lambda : map(int, input().split())
for i in range(int(input())):
	(a, b, n) = R()
	c = a ^ b
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(c)


for i in range(int(input())):
	(a, b, n) = map(int, input().split())
	f = []
	f.append(a)
	f.append(b)
	ans = a ^ b
	f.append(ans)
	print(f[n % 3])


T = int(input())
for _ in range(T):
	(a, b, n) = list(map(int, input().split()))
	mod = n % 3
	if mod == 0:
		print(a)
	elif mod == 1:
		print(b)
	elif mod == 2:
		print(a ^ b)


t = int(input(''))
f = [0, 0, 0]
for i in range(0, t):
	(f[0], f[1], n) = [int(x) for x in str(input('')).split(' ')]
	f[2] = f[0] ^ f[1]
	print(f[n % 3])


t = int(input())
while t:
	t -= 1
	(a, b, n) = map(int, input().split())
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)


q_input = int(input())
for _ in range(q_input):
	(a, b, n) = map(int, input().split())
	result = [a, b, a ^ b]
	print(result[n % 3])


T = int(input())
for i in range(T):
	(a, b, n) = map(int, input().split())
	print([a, b, a ^ b][n % 3])


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	m = a ^ b
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	elif n % 3 == 0:
		print(a)
	elif (n - 1) % 3 == 0:
		print(b)
	else:
		print(m)


import sys

def xornachi(a, b, n):
	return [a, b, a ^ b][n % 3]
tests = sys.stdin.readlines()
for line in tests[1:]:
	(a, b, n) = [int(elem) for elem in line.split(' ')]
	print(xornachi(a, b, n))


from operator import xor
t = int(input())
for _ in range(t):
	(a, b, n) = map(int, input().split())
	f = [a, b, a ^ b]
	print(f[n % 3])


t = int(input())
for i in range(t):
	x = [0] * 3
	(x[0], x[1], n) = map(int, input().split())
	x[2] = x[1] ^ x[0]
	if n <= 1:
		print(x[n])
	else:
		print(x[n % 3])


t = int(input())
arr = [None] * t
for i in range(t):
	arr[i] = list(map(int, input().split(' ')))

def f(a, b, n):
	if n % 3 == 0:
		return a
	elif n % 3 == 1:
		return b
	elif n % 3 == 2:
		return a ^ b
for i in range(t):
	print(f(arr[i][0], arr[i][1], arr[i][2]))


from sys import stdin

def slowXor(a, b, n):
	res = [a, b]
	for i in range(2, n + 1):
		res.append(res[i - 1] ^ res[i - 2])
	print(res[n])

def xor(a, b, n):
	res = [a, b, a ^ b]
	print(res[n % 3])
allData = int(stdin.readline())
while allData > 0:
	(a, b, n) = stdin.readline().split()
	allData -= 1
	xor(int(a), int(b), int(n))


t = int(input())
for i in range(t):
	(a, b, c) = input().strip().split(' ')
	(a, b, c) = [int(a), int(b), int(c)]
	x = [a, b, a ^ b]
	print(x[c % 3])


def XORinacci(s0, s1, n):
	if n < 1:
		return s0
	elif n == 1:
		return s1
	else:
		return XORinacci(s0, s1, n - 1) ^ XORinacci(s0, s1, n - 2)
num = int(input())
ins = []
for i in range(num):
	x = [int(x) for x in input().split()]
	ins.append(x)
for i in range(num):
	print(XORinacci(ins[i][0], ins[i][1], ins[i][2] % 3))


t = int(input())
ans = []
for i in range(t):
	(a, b, n) = (int(i) for i in input().split())
	if n % 3 == 0:
		ans.append(a)
	elif n % 3 == 1:
		ans.append(b)
	else:
		k = a ^ b
		ans.append(k)
for i in ans:
	print(i)


ans = []
f = [0, 0, 0]
k = input()
for x in range(int(k)):
	a = input()
	a = a.split(' ')
	n = int(a.pop())
	f[1] = int(a.pop())
	f[0] = int(a.pop())
	f[2] = f[0] ^ f[1]
	ans.append(f[n % 3])
for x in range(int(k)):
	print(ans[x])


for _ in range(int(input())):
	(a, b, n) = [int(x) for x in input().split()]
	if n % 3 == 0:
		print(a)
	elif n % 3 == 2:
		print(a ^ b)
	else:
		print(b)


t = int(input())
for i in range(0, t):
	(a, b, c) = input().split()
	a = int(a)
	b = int(b)
	c = int(c)
	if c % 3 == 0:
		print(a)
	elif c % 3 == 1:
		print(b)
	else:
		print(a ^ b)


def func(x, y, number):
	if n % 3 == 0:
		return a
	elif n % 3 == 1:
		return b
	else:
		return a ^ b
for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	print(func(a, b, n))


t = int(input())
for k in range(t):
	(a, b, n) = list(map(int, input().split()))
	res = [a, b, a ^ b]
	print(res[n % 3])


T = int(input())
for _ in range(T):
	[a, b, N] = [int(x) for x in input().split()]
	sk = [a, b, a ^ b]
	print(sk[N % 3])


import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt
args = None
INF = float('inf')
MOD = int(1000000000.0 + 7)

def input(*ps):
	if type(ps[0]) is list:
		return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
	elif len(ps) == 1:
		return ps[0](next(args))
	else:
		return [p(next(args)) for p in ps]

def nlist(n, v):
	if not n:
		return v.copy()
	return [nlist(n[1:], v) for _ in range(n[0])]

def main():
	N = input(int)
	for _ in range(N):
		(A, B, C) = input([int, 3])
		if C == 0:
			print(A)
			continue
		if C == 1:
			print(B)
			continue
		ans = 0
		mask = 1 << 32
		while mask:
			(a, b) = (A & mask, B & mask)
			ans += [a, b, a ^ b][C % 3]
			mask >>= 1
		print(ans)
args = iter(sys.stdin.read().split())
main()


def nacci(a, b, n):
	n = n % 3
	if n == 0:
		return a
	if n == 1:
		return b
	return a ^ b
t = int(input())
for i in range(t):
	(a, b, n) = list(map(int, input().rstrip().split()))
	print(nacci(a, b, n))


for j in range(int(input())):
	(a, b, n) = list(map(int, input().split()))
	if n % 3 == 2:
		print(a ^ b)
	elif n % 3 == 1:
		print(b)
	else:
		print(a)


def xorinacci(n, a, b):
	if n % 3 == 0:
		return a
	elif n % 3 == 1:
		return b
	else:
		return a ^ b
q = int(input())
for i in range(q):
	(a, b, n) = map(int, input().split())
	print(xorinacci(n, a, b))


for _ in range(int(input())):
	(a, b, n) = list(map(int, input().split()))
	c = a ^ b
	if n % 3 == 0:
		print(a)
	if n % 3 == 1:
		print(b)
	if n % 3 == 2:
		print(c)


def solve():
	d = {}
	[d[0], d[1], n] = list(map(int, input().split()))
	d[2] = d[0] ^ d[1]
	print(d[n] if n in d else d[(n - 3) % 3])
for i in range(int(input())):
	solve()


def f(a, b, n):
	if n % 3 == 0:
		return a
	elif n % 3 == 1:
		return b
	else:
		return a ^ b
ans = []
nt = int(input())
for i in range(nt):
	(a, b, n) = input().split()
	ans.append(f(int(a), int(b), int(n)))
for i in ans:
	print(i)


t = int(input())
for i in range(0, t):
	b = []
	b.append(list(map(int, input().split())))
	x = b[0][0] ^ b[0][1]
	n = b[0][2]
	if n % 3 == 0:
		print(b[0][0])
	if n % 3 == 1:
		print(b[0][1])
	if n % 3 == 2:
		print(x)


import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def inc(d, c):
	d[c] = d[c] + 1 if c in d else 1

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < n

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	(a, b, n) = mi()
	n += 1
	if n % 3 == 0:
		print(a ^ b)
	elif n % 3 == 1:
		print(a)
	else:
		print(b)


import sys
T = int(input())
for j in range(T):
	(a, b, n) = (int(i) for i in input().split(' '))
	n_ = n % 3
	if n_ == 0:
		print(a)
	elif n_ == 1:
		print(b)
	else:
		print(a ^ b)


def solve(a, b, n):
	return (a, b, a ^ b)[n % 3]

def main():
	t = int(input())
	for _ in range(t):
		(a, b, n) = map(int, input().split())
		print(solve(a, b, n))
main()


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
T = int(input())
for t in range(T):
	(a, b, n) = map(int, input().split())

	def solve(a, b, n):
		n %= 3
		if n == 0:
			return a
		elif n == 1:
			return b
		else:
			return a ^ b
	print(str(solve(a, b, n)) + '\n')


t = int(input())
while t:
	t = t - 1
	(a, b, n) = map(int, input().split())
	l = [a, b, a ^ b]
	print(l[n % 3])


t = int(input())
ass = []
bs = []
ns = []
for i in range(t):
	(a, b, n) = map(int, input().split(' '))
	ass.append(a)
	bs.append(b)
	ns.append(n)
for i in range(t):
	if ns[i] % 3 == 0:
		print(ass[i])
	elif ns[i] % 3 == 1:
		print(bs[i])
	else:
		print(ass[i] ^ bs[i])


t = int(input())
while t:
	(a, b, n) = map(int, input().split())
	ans = (n + 1) % 3
	if ans == 1:
		print(a)
	elif ans == 2:
		print(b)
	else:
		print(a ^ b)
	t = t - 1


q = int(input())
for i in range(q):
	(a, b, n) = map(int, input().split())
	c = [a, b, a ^ b]
	print(c[n % 3])


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		(a, b, n) = map(int, input().split())
		A = [a, b, a ^ b]
		print(A[n % 3])
main()


import sys

def xornachi(a, b, c):
	if c < 1:
		return a
	elif c == 1:
		return b
	bit_tuples = []
	while a > 0 or b > 0:
		bit_tuples.append((a & 1, b & 1))
		a >>= 1
		b >>= 1
	c_bits = []
	for (a_bit, b_bit) in bit_tuples:
		c_bit = 0
		if (a_bit, b_bit) == (0, 0):
			pass
		elif (a_bit, b_bit) == (0, 1):
			if c % 3 == 2:
				c_bit = 1
			elif c % 3 == 0:
				c_bit = 0
			else:
				c_bit = 1
		elif (a_bit, b_bit) == (1, 0):
			if c % 3 == 2:
				c_bit = 1
			elif c % 3 == 0:
				c_bit = 1
			else:
				c_bit = 0
		elif (a_bit, b_bit) == (1, 1):
			if c % 3 == 2:
				c_bit = 0
			elif c % 3 == 0:
				c_bit = 1
			else:
				c_bit = 1
		else:
			assert False
		c_bits.append(c_bit)
	ans = 0
	for (i, c_bit) in enumerate(c_bits):
		ans += c_bit << i
	return ans
tests = sys.stdin.readlines()
for line in tests[1:]:
	(a, b, c) = [int(elem) for elem in line.split(' ')]
	print(xornachi(a, b, c))


for _ in range(int(input())):
	(a, b, n) = (int(s) for s in input().split())
	l = [a, b, a ^ b]
	print(l[n % 3])


q = int(input())
while q > 0:
	q -= 1
	(a, b, c) = map(int, input().split())
	if c == 0:
		print(a)
	elif c == 1:
		print(b)
	else:
		c -= 1
		if c % 3 == 0:
			print(b)
		elif (c + 1) % 3 == 0:
			print(a)
		else:
			print(a ^ b)


import sys, atexit
from io import BytesIO
inp = BytesIO(sys.stdin.buffer.read())
input = lambda : inp.readline().decode('ascii')
buf = BytesIO()
atexit.register(lambda : sys.__stdout__.buffer.write(buf.getvalue()))
for i in range(int(input())):
	(a, b, n) = map(int, input().split())
	x = n % 3
	if x == 2:
		print(a ^ b)
	elif x == 0:
		print(a)
	elif x == 1:
		print(b)


t = int(input())
for i in range(t):
	a = [int(i) for i in input().split()]
	n = a[2]
	a[2] = a[1] ^ a[0]
	print(a[n % 3])


def xorfib(a, b, n):
	if n % 3 == 0:
		return a
	if n % 3 == 1:
		return b
	return a ^ b
cases = int(input())
for i in range(cases):
	(a, b, n) = [int(x) for x in input().split()]
	print(xorfib(a, b, n))


def I():
	return int(input())

def IM():
	return map(int, input().split())

def IL():
	return [int(i) for i in input().split()]

def IS():
	return input()
for _ in range(I()):
	(a, b, n) = IM()
	n += 1
	curr = n % 3
	rem = n % 3
	if rem == 0:
		print(a ^ b)
	if rem == 1:
		print(a)
	if rem == 2:
		print(b)


def findNthTerm(a, b, n):
	k = n % 3
	if k == 0:
		return a
	elif k == 1:
		return b
	else:
		return a ^ b
t = int(input())
while t > 0:
	t -= 1
	(a, b, n) = map(int, input().split())
	ans = findNthTerm(a, b, n)
	print(ans)


tests = int(input())
for i in range(tests):
	(a, b, n) = map(int, input().split())
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	elif (n + 1) % 3 == 0:
		print(b ^ a)
	elif (n - 1) % 3 == 0:
		print(b)
	elif n % 3 == 0:
		print(a)


for i in range(int(input())):
	(a, b, n) = map(int, input().split())
	dic = {0: a, 1: b, 2: a ^ b}
	print(dic[n % 3])


T = int(input())
for i in range(0, T):
	ln = [int(j) for j in input().split(' ')]
	lns = [ln[0], ln[1], ln[0] ^ ln[1]]
	print(lns[ln[2] % 3])


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
for y in range(t):
	(a, b, n) = map(int, input().split())
	l = [a, b, a ^ b]
	print(l[n % 3])


for i in range(int(input())):
	(*a, c) = map(int, input().split())
	a.append(a[0] ^ a[1])
	print(a[c % 3])


N = int(input())
a = []
r = []
for _ in range(N):
	a.append([int(x) for x in input().split()])
for (a, b, n) in a:
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	else:
		d = {(a, b): 0}
		for i in range(n - 1):
			(a, b) = (b, a ^ b)
			if (a, b) in d:
				k = d[a, b]
				l = i + 1
				r = (n - k) % (l - k)
				if r == 0:
					b = a
				elif r == 1:
					pass
				else:
					for _ in range(r - 1):
						(a, b) = (b, a ^ b)
				break
			else:
				d[a, b] = i + 1
		print(b)


a = int(input())
for i in range(a):
	(q, w, e) = map(int, input().split())
	r = q ^ w
	A = [q, w, r]
	print(A[e % 3])


def f(a, b, n):
	r = n % 3
	if r == 2:
		return a ^ b
	elif r == 1:
		return b
	else:
		return a
params = []
for _ in range(int(input())):
	params.append(map(int, input().split()))
for param in params:
	print(f(*param))


T = int(input())
k = 1

def XOR(a, b, n):
	if n % 3 == 0:
		return a
	elif n % 3 == 1:
		return b
	else:
		return a ^ b
while k <= T:
	vvod = input()
	c = [int(x) for x in vvod.split()]
	print(XOR(c[0], c[1], c[2]))
	k += 1


import sys
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
T = int(input())
while T > 0:
	(a, b, n) = get_ints()
	n = n % 3
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	else:
		print(a ^ b)
	T -= 1


def problem():
	T = int(input())
	while T:
		inp = input().split(' ')
		a = int(inp[0])
		b = int(inp[1])
		n = int(inp[2])
		if n == 0:
			print(a)
		elif n == 1:
			print(b)
		elif n == 2:
			print(a ^ b)
		elif n % 3 == 0:
			print(a)
		elif n % 3 == 1:
			print(b)
		else:
			print(a ^ b)
		T = T - 1
problem()


cases = int(input())
for case in range(1, cases + 1):
	(a, b, n) = [int(i) for i in input().split()]
	if n == 0:
		print(a)
		continue
	elif n == 1:
		print(b)
		continue
	elif n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(b ^ a)


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	k = 0
	x = [a, b]
	k = x[0] ^ x[1]
	x.append(k)
	if n % 3 == 0:
		print(x[0])
	elif n % 3 == 1:
		print(x[1])
	else:
		print(x[2])


i = input
exec(int(i()) * 'a,b,n=map(int,i().split());print([a,b,a^b][n%3]);')


T = int(input())
inls = []
for i in range(T):
	inp = input()
	tup = list(inp.split())
	inls.append(tup)
for i in inls:
	a = int(i[0])
	b = int(i[1])
	n = int(i[2])
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	elif n % 3 == 2:
		print(a ^ b)


t = int(input())
while t != 0:
	(a, b, n) = [int(i) for i in input().split()]
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)
	t -= 1


class XORinacci:

	def __init__(self):
		self.NoOfTestCases = 0

	def getInputData(self):
		self.NoOfTestCases = int(input())
		testCase = [0, 0, 0]
		for x in range(self.NoOfTestCases):
			strTestCase = str(input()).split(' ')
			testCase[0] = int(strTestCase[0])
			testCase[1] = int(strTestCase[1])
			testCase[2] = int(strTestCase[2])
			self.computeXORinacii(testCase)

	def computeXORinacii(self, testCase):
		xor = testCase[0] ^ testCase[1]
		if testCase[2] % 3 == 0:
			print(testCase[0])
		elif testCase[2] % 3 == 1:
			print(testCase[1])
		else:
			print(xor)
x = XORinacci()
x.getInputData()


n = int(input())
for i in range(n):
	f = [0] * 3
	(f[0], f[1], n) = map(int, input().split())
	f[2] = f[1] ^ f[0]
	if n <= 1:
		print(f[n])
	else:
		print(f[n % 3])


t = int(input())
for i in range(0, t):
	ints = input().split()
	a = int(ints[0])
	b = int(ints[1])
	n = int(ints[2])
	c = a ^ b
	nmod = n % 3
	if nmod == 0:
		nextint = a
	elif nmod == 1:
		nextint = b
	else:
		nextint = c
	print(nextint)


for t in range(int(input())):
	(a, b, n) = map(int, input().split())
	if n == 0:
		print(a)
		continue
	if n == 1:
		print(b)
		continue
	list1 = [a, b, a ^ b]
	print(list1[n % 3])


def solve(a, b, n):
	if n % 3 == 0:
		return a
	elif n % 3 == 1:
		return b
	else:
		return a ^ b

def main():
	for _ in range(int(input())):
		(a, b, n) = list(map(int, input().split()))
		print(solve(a, b, n))
main()


Q = int(input())
for q in range(Q):
	(a, b, c) = tuple(map(int, input().split()))
	p = c % 3
	if p == 0:
		print(a)
	elif p == 1:
		print(b)
	else:
		print(a ^ b)


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	ans = [0] * 3
	ans[0] = a
	ans[1] = b
	ans[2] = a ^ b
	print(ans[n % 3])


import math

def solve_digit(a, b, n):
	if a == 0 and b == 0:
		return 0
	elif a == 0 and b == 1:
		p = [0, 1, 1]
		return p[n % 3]
	elif a == 1 and b == 0:
		p = [1, 0, 1]
		return p[n % 3]
	else:
		p = [1, 1, 0]
		return p[n % 3]

def solve(a, b, n):
	result = 0
	d = 1
	while a > 0 or b > 0:
		result += d * solve_digit(a & 1, b & 1, n)
		d <<= 1
		a >>= 1
		b >>= 1
	return result

def main():
	t = int(input())
	for i in range(t):
		(a, b, n) = tuple([int(x) for x in input().split()])
		print(solve(a, b, n))
main()


def fibo(a, b, n):
	if n == 0:
		return a
	elif n == 1:
		return b
	elif n == 2:
		return a ^ b
	else:
		return fibo(a, b, n % 3)
t = int(input())
while t:
	(a, b, n) = map(int, input().split())
	print(fibo(a, b, n))
	t -= 1


for i in range(int(input())):
	(a, b, naz) = map(int, input().split())
	if naz % 3 == 0:
		print(a)
	elif naz % 3 == 1:
		print(b)
	else:
		print(a ^ b)


T = int(input())
for _ in range(T):
	(f0, f1, n) = map(int, input().split())
	fn = f0 ^ f1
	if n % 3 == 0:
		print(f0)
	elif n % 3 == 1:
		print(f1)
	else:
		print(fn)


n = int(input())
for i in range(0, n):
	p = input().rstrip().split(' ')
	a = int(p[0])
	b = int(p[1])
	c = int(p[0]) ^ int(p[1])
	if int(p[2]) == 0:
		print(a)
	elif int(p[2]) == 1:
		print(b)
	elif int(p[2]) % 3 == 0:
		print(a)
	elif int(p[2]) % 3 == 1:
		print(b)
	else:
		print(c)


t = int(input())
for i2 in range(t):
	(a, b, n) = map(int, input().split())
	x = [a, b, a ^ b]
	print(x[n % 3])


def solve(a, b, n):
	for i in range(n % 3):
		(a, b) = (b, a ^ b)
	return a
[print(solve(*map(int, input().split()))) for _ in range(int(input()))]


t = int(input())
while t:
	t -= 1
	(a, b, c) = map(int, input().split())
	d = a ^ b
	if c % 3 == 0:
		print(a)
	if c % 3 == 1:
		print(b)
	if c % 3 == 2:
		print(d)


t = int(input())
for test in range(t):
	(a, b, n) = list(map(int, input().split()))
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)


def f(a, b, n):
	n %= 3
	if n == 0:
		return a
	if n == 1:
		return b
	return b ^ a
for _ in range(int(input())):
	print(f(*map(int, input().split())))


n = int(input())
for i in range(n):
	s = input().split(' ')
	a0 = int(s[0])
	a1 = int(s[1])
	rez = int(s[2]) % 3
	if rez == 0:
		print(a0)
		continue
	if rez == 1:
		print(a1)
		continue
	if rez == 2:
		print(a0 ^ a1)


t = int(input())
for i in range(t):
	(a, b, n) = list(map(int, input().strip().split()))
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	elif n % 3 == 2:
		print(a ^ b)


import math
import sys
from collections import defaultdict
rt = lambda : map(int, input().split())
ri = lambda : int(input())

def main():
	t = ri()
	for _ in range(t):
		(a, b, n) = rt()
		n %= 3
		if n == 0:
			res = a
		elif n == 1:
			res = b
		else:
			res = a ^ b
		print(res)
main()


T = int(input())
for t in range(T):
	(a, b, n) = [int(i) for i in input().split()]
	if n % 3 == 2:
		print(a ^ b)
	elif n % 3 == 1:
		print(b)
	else:
		print(a)


import math
T = int(input())
for _ in range(T):
	(a, b, n) = map(int, input().split(' '))
	A = [a, b, a ^ b]
	print(A[n % 3])


def xorinacci(a, b, n):
	possible = [a, b, a ^ b]
	return possible[n % 3]
T = int(input().rstrip())
for _ in range(T):
	(a, b, n) = map(int, input().rstrip().split())
	print(xorinacci(a, b, n))


test = int(input())
while test > 0:
	test -= 1
	(a, b, n) = map(int, input().split())
	fib = [a, b, a ^ b]
	print(fib[n % 3])


def XORinacci(a, b, n):
	if n == 0:
		return a
	if n == 1:
		return b
	if n == 2:
		return a ^ b
	return XORinacci(a, b, n % 3)
x = []
t = int(input())
for i in range(t):
	s = input()
	l = s.split()
	a = int(l[0])
	b = int(l[1])
	n = int(l[2])
	x.append(XORinacci(a, b, n))
for i in x:
	print(i)


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	y = a ^ b
	x = [a, b, y]
	print(x[n % 3])


class DisjointSet:

	def __init__(self, N):
		super().__init__()
		self.N = N
		self.parent = [i for i in range(self.N)]
		self.rank = [0 for i in range(self.N)]

	def find(self, x):
		temp = x
		while self.parent[temp] != temp:
			temp = self.parent[temp]
		self.parent[x] = temp
		return self.parent[x]

	def union(self, x, y):
		repx = self.find(x)
		repy = self.find(y)
		if repx == repy:
			return
		elif self.rank[repx] < self.rank[repy]:
			self.parent[repx] = repy
		elif self.rank[repx] > self.rank[repy]:
			self.parent[repy] = repx
		else:
			self.parent[repx] = repy
			self.rank[repy] += 1
		return

def mergeSort(l, r, arr, reverse=False, cmp=lambda x, y: x <= y):
	if r - l == 1:
		return arr[l:r]
	mid = (r + l) // 2
	arr1 = mergeSort(l, mid, arr)
	arr2 = mergeSort(mid, r, arr)
	(i, j) = (0, 0)
	while i < mid - l and j < r - mid:
		if not reverse and cmp(arr1[i], arr2[j]) or (reverse and (not cmp(arr1[i], arr2[j]))):
			arr[i + j] = arr1[i]
			i += 1
		else:
			arr[i + j] = arr2[j]
			j += 1
	while i < mid - l:
		arr[i + j] = arr1[i]
		i += 1
	while j < r - mid:
		arr[i + j] = arr2[j]
		j += 1
	return arr[:]
T = int(input())
for test_case in range(T):
	(a, b, n) = map(int, input().split())
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)


t = int(input())
for _ in range(t):
	(a, b, n) = input().split()
	a = int(a)
	b = int(b)
	n = int(n)
	n1 = a ^ b
	n = n + 1
	if n % 3 == 0:
		print(n1)
	elif n % 3 == 1:
		print(a)
	elif n % 3 == 2:
		print(b)


for i in range(int(input())):
	(a, b, n) = [int(x) for x in input().split(' ')]
	print([a, b, a ^ b][n % 3])


t = int(input())
for u in range(t):
	x = [int(i) for i in input().split()]
	(a, b) = (x[0], x[1])
	v = a ^ b
	dp = [a, b, v]
	print(dp[x[2] % 3])


for case in range(int(input())):
	(a, b, t) = map(int, input().split())
	if t % 3 == 0:
		print(a)
	elif t % 3 == 1:
		print(b)
	else:
		print(a ^ b)


T = int(input())
ans_arr = []
for _ in range(T):
	arr = list(map(int, input().split()))
	(a, b, n) = (arr[0], arr[1], arr[2])

	def xor(n):
		if n == 0:
			return a
		elif n == 1:
			return b
		sm = a
		bg = b
		ans = sm ^ bg
		for i in range(2, n):
			sm = bg
			bg = ans
			ans = sm ^ bg
		return ans
	if n % 3 == 0:
		t = xor(3)
	if n % 3 == 1:
		t = xor(4)
	if n % 3 == 2:
		t = xor(5)
	ans_arr.append(t)
for el in ans_arr:
	print(el)


def fib(a, b, n):
	remainder = n % 3
	if remainder == 0:
		return a
	elif remainder == 1:
		return b
	else:
		return a ^ b
t = int(input())
for _ in range(t):
	(a, b, n) = map(int, input().split())
	print(fib(a, b, n))


t = int(input())
for i in range(0, t):
	f = [int(d) for d in input().split()]
	if f[2] % 3 == 0:
		print(f[0])
	elif f[2] % 3 == 1:
		print(f[1])
	else:
		print(f[0] ^ f[1])


n = int(input())
for i in range(n, 0, -1):
	a = list(map(int, input().split()))
	if a[2] % 3 == 2:
		print(a[0] ^ a[1])
	else:
		print(a[0] if a[2] % 3 == 0 else a[1])


def fib():
	if n == 0:
		return f0
	return f0 ^ f1 if n % 3 == 2 else f1 if n % 3 == 1 else f0
numTests = int(input())
for i in range(numTests):
	(f0, f1, n) = map(int, input().split())
	print(fib())


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	l = [a, b]
	c = a ^ b
	l.append(c)
	print(l[n % 3])


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from heapq import heappush as hpush
from heapq import heappop as hpop
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())

def f(n):
	if n == 0:
		return a
	if n == 1:
		return b
	else:
		return f(n - 1) ^ f(n - 2)
for _ in range(ri(1)):
	(a, b, n) = ri()
	take = [a, b]
	if n % 3 == 0:
		print(a)
	if n % 3 == 1:
		print(b)
	if n % 3 == 2:
		print(a ^ b)


def main():
	t = int(input())
	for i in range(t):
		(a, b, n) = map(int, input().split())
		s1 = list(bin(a)[2:])
		s2 = list(bin(b)[2:])
		ans = 0
		prod = 1
		s3 = [0 for i in range(max(len(s1), len(s2)))]
		for i in range(max(len(s1), len(s2))):
			if i < len(s1) and i < len(s2):
				if s1[-i - 1] == '1' and s2[-i - 1] == '1':
					s3[-i - 1] = 0
				if s1[-i - 1] == '0' and s2[-i - 1] == '1':
					s3[-i - 1] = 1
				if s1[-i - 1] == '1' and s2[-i - 1] == '0':
					s3[-i - 1] = 1
				if s1[-i - 1] == '0' and s2[-i - 1] == '0':
					s3[-i - 1] = 0
			elif i < len(s1):
				s3[-i - 1] = int(s1[-i - 1])
			else:
				s3[-i - 1] = int(s2[-i - 1])
		for i in range(len(s3) - 1, -1, -1):
			if s3[i] == 1:
				ans += prod
			prod *= 2
		if n % 3 == 0:
			print(a)
		elif n % 3 == 1:
			print(b)
		else:
			print(ans)
main()


t = int(input())
arr = []
for i in range(0, t):
	b = []
	s = input() + ' '
	crnt = ''
	for c in s:
		if c == ' ':
			b.append(int(crnt))
			crnt = ''
		else:
			crnt += c
	arr.append(b)
for a in arr:
	f = [a[0], a[1], a[0] ^ a[1]]
	print(f[a[2] % 3])


def f(a, b, n):
	r = n % 3
	if r == 2:
		return a ^ b
	elif r == 1:
		return b
	else:
		return a

def codeforces():
	params = []
	for _ in range(int(input())):
		params.append(map(int, input().split()))
	for param in params:
		print(f(*param))

def test():
	assert f(3, 4, 2) == 7
	assert f(4, 5, 0) == 4
	assert f(325, 265, 1231232) == 76
codeforces()


for _ in range(int(input())):
	l = list(map(int, input().split()))
	(a, b, n) = (l[0], l[1], l[2])
	if (n + 1) % 3 is 1:
		print(a)
	elif (n + 1) % 3 is 2:
		print(b)
	else:
		print(a ^ b)


T = int(input())
for i in range(T):
	(f_0, f_1, n) = map(int, input().split())
	if n % 3 == 0:
		print(f_0)
	elif n % 3 == 1:
		print(f_1)
	else:
		print(f_0 ^ f_1)


t = int(input().strip())
while t > 0:
	l = list(map(int, input().split(' ')))
	if l[2] % 3 == 0:
		print(l[0])
	elif l[2] % 3 == 1:
		print(l[1])
	else:
		print(l[0] ^ l[1])
	t = t - 1


t = int(input())
for _ in range(t):
	v = [0, 0, 0]
	(v[0], v[1], n) = map(int, input().split())
	v[2] = v[0] ^ v[1]
	print(v[n % 3])


def main():
	t = int(input())
	for i in range(t):
		(a, b, n) = map(int, input().split())
		if (n + 1) % 3 == 2:
			print(b)
		elif (n + 1) % 3 == 1:
			print(a)
		else:
			print(a ^ b)
main()


test = int(input())
while test:
	test -= 1
	(a, b, n) = list(map(int, input().split()))
	m = n % 3
	if m == 0:
		print(a)
	elif m == 1:
		print(b)
	else:
		print(a ^ b)


print(*[(lambda a: (a[0], a[1], a[0] ^ a[1])[a[2] % 3])(list(map(int, input().split()))) for _ in range(int(input()))], sep='\n', end='\n')


for t in range(int(input())):
	(a, b, n) = map(int, input().split())
	k = n % 3
	if k == 2:
		print(a ^ b)
	elif k == 1:
		print(b)
	else:
		print(a)


def isMember(a, d, n):
	if d == 0:
		return n == a
	return (n - a) % d == 0 and (n - a) / d >= 0
t = int(input())
for test in range(t):
	(a, b, n) = [int(x) for x in input().split()]
	if isMember(0, 3, n):
		print(a)
	if isMember(1, 3, n):
		print(b)
	if isMember(2, 3, n):
		print(a ^ b)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	b = a[2] % 3
	a[2] = a[0] ^ a[1]
	print(a[b])


T = int(input())
for t in range(T):
	(a, b, n) = [int(x) for x in input().split()]
	if n == 0:
		print(a)
		next
	elif n == 1:
		print(b)
		next
	elif n % 3 == 2:
		print(a ^ b)
	elif n % 3 == 0:
		print(a)
	else:
		print(b)


entrada = int(input())
for lala in range(entrada):
	(a, b, n) = [int(i) for i in input().split()]
	c = a ^ b
	resto = n % 3
	if resto == 0:
		print(a)
	elif resto == 1:
		print(b)
	else:
		print(c)


for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	arr = [0] * 4
	arr[0] = a
	arr[1] = b
	arr[2] = a ^ b
	print(arr[n % 3])


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	x = list(bin(a))
	y = list(bin(b))
	(x[1], y[1]) = ('0', '0')
	k = []
	if len(x) < len(y):
		for i in range(len(y) - len(x)):
			x.insert(0, '0')
	if len(y) < len(x):
		for i in range(len(x) - len(y)):
			y.insert(0, '0')
	t = 0
	for i in range(max(len(x), len(y)) - 2):
		if x[-1 - i] == y[-i - 1]:
			t += 0
		else:
			t += 2 ** i
	if c % 3 == 0:
		print(a)
	elif c % 3 == 1:
		print(b)
	else:
		print(t)


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getArr():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
t = getInt()
for _ in range(t):
	(a, b, n) = getVars()
	a2 = bin(a)[2:]
	b2 = bin(b)[2:]
	m = max(len(a2), len(b2))
	a2 = '0' * (m - len(a2)) + a2
	b2 = '0' * (m - len(b2)) + b2
	s = ''
	for i in range(m):
		if a2[i] == '0' and b2[i] == '0':
			s += '0'
		else:
			ost = n % 3
			if ost == 0:
				s += a2[i]
			if ost == 1:
				s += b2[i]
			if ost == 2:
				s += str((int(a2[i]) + int(b2[i])) % 2)
	print(int(s, base=2))


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(a, b, n) = [int(i) for i in input().split()]
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)


t = int(input())
for q in range(t):
	(a, b, n) = map(int, input().split())
	if n % 3 == 2:
		print(a ^ b)
	elif n % 3 == 0:
		print(a)
	else:
		print(b)


from sys import stdin
t = int(stdin.readline().strip())
for _ in range(t):
	(a, b, n) = list(map(int, stdin.readline().split()))
	arr = [a, b, b ^ a, b ^ a ^ b, b, a ^ b]
	n = n % 6
	print(arr[n])


def to_bi(num):
	lst = []
	while num > 0:
		lst.append(num % 2)
		num //= 2
	return lst

def xor(a1, b1):
	l = max(len(a1), len(b1))
	ans = []
	for k in range(abs(len(a1) - len(b1))):
		a1.append(0)
		b1.append(0)
	for k in range(l):
		if a1[k] == b1[k]:
			ans.append(0)
		else:
			ans.append(1)
	return ans

def to_dec(lst):
	ans = 0
	for i in range(len(lst)):
		ans += 2 ** i * lst[i]
	return ans
t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	if (n + 1) % 3 == 0:
		print(to_dec(xor(to_bi(a), to_bi(b))))
	elif (n + 1) % 3 == 2:
		print(b)
	else:
		print(a)


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		ab = ''
		bb = ''
		cb = ''
		while a != 0:
			ab += str(a % 2)
			a = a // 2
		while b != 0:
			bb += str(b % 2)
			b = b // 2
		if len(ab) != len(bb):
			if len(ab) < len(bb):
				ab += '0' * (len(bb) - len(ab))
			else:
				bb += '0' * (len(ab) - len(bb))
		ab = ab[::-1]
		bb = bb[::-1]
		for i in range(len(bb)):
			cb += str((int(ab[i]) + int(bb[i])) % 2)
		E = 0
		for i in range(len(cb)):
			E += int(cb[i]) * 2 ** (len(cb) - 1 - i)
		print(E)


def xorinacci(a, b, n):
	if n % 3 == 0:
		return a
	elif n % 3 == 1:
		return b
	elif n % 3 == 2:
		return a ^ b
for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	print(xorinacci(a, b, n))


def findXORInAcci(a, b, n):
	n = n % 3
	if n == 0:
		return a
	elif n == 1:
		return b
	return a ^ b
T = int(input())
for _ in range(T):
	ABN = input().split(' ')
	a = int(ABN[0])
	b = int(ABN[1])
	n = int(ABN[2])
	print(findXORInAcci(a, b, n))


dif = [0, 0, 2, 1]
T = int(input())
for t in range(T):
	(a, b, n) = map(int, input().split())
	i = 1
	res = 0
	while (a > 0) | (b > 0):
		c = ((a & 1) << 1) + (b & 1)
		if (c != 0) & ((n + dif[c]) % 3 != 0):
			res += i
		i <<= 1
		a >>= 1
		b >>= 1
	print(res)


a = int(input())
for i in range(a):
	k = [int(i) for i in input().split()]
	if k[2] == 0:
		print(k[0])
	elif k[2] == 1:
		print(k[1])
	else:
		d = k[0] ^ k[1]
		if k[2] % 3 == 0:
			print(k[0])
		elif k[2] % 3 == 1:
			print(k[1])
		else:
			print(d)


def fib(a, b, n):
	if n == 0:
		return a
	elif n == 1:
		return b
	elif n == 2:
		return a ^ b
	else:
		return fib(a, b, n % 3)
j = int(input())
i = 0
while i < j:
	entrada = input()
	n = entrada.split(' ')
	a = int(n[0])
	b = int(n[1])
	n = int(n[2])
	res = fib(a, b, n)
	print(res)
	i += 1


def xor(a, b):
	return a ^ b
t = int(input())
for i in range(1, t + 1, 1):
	(a, b, c) = map(int, input().split())
	c %= 3
	if c == 0:
		print(a)
	elif c == 1:
		print(b)
	else:
		print(xor(a, b))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	(a, b, n) = map(int, input().split())
	l = [a, b, a ^ b]
	print(l[n % 3])


def solve():
	(a, b, n) = map(int, input().split())
	c = a ^ b
	arr = [a, b, c]
	print(arr[n % 3])
for i in range(int(input())):
	solve()


case = int(input())
while case != 0:
	case -= 1
	(f, b, n) = [int(x) for x in input().split()]
	if n % 3 == 2:
		ans = f ^ b
	elif n % 3 == 1:
		ans = b
	elif n % 3 == 0:
		ans = f
	print(ans)


def main():
	(a, b, n) = [int(i) for i in input().split(' ')]
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)
for _ in range(int(input())):
	main()


def xorinacci(a, b, n):
	if n == 0:
		return a
	if n == 1:
		return b
	if n == 2:
		return a ^ b
t = int(input())
while t > 0:
	t -= 1
	(a, b, n) = map(int, input().split())
	print(xorinacci(a, b, n % 3))


for _ in range(int(input())):
	num = list(map(int, input().split()))
	(n, num[-1]) = (num[-1], num[0] ^ num[1])
	print(num[n % 3])


def xorinacci(a, b, n):
	if n == 0:
		return a
	if n == 1:
		return b
	binA = bin(a)
	binB = bin(b)
	difLen = len(binA) - len(binB)
	if difLen < 0:
		binA = '0b' + '0' * -difLen + binA[2:]
	else:
		binB = '0b' + '0' * difLen + binB[2:]
	binAux = '0b'
	for i in range(2, len(binA)):
		if binA[i] == binB[i] == '0':
			binAux += '0'
			continue
		if binA[i] == '0' and binB[i] == '1':
			remainder = 0
		elif binA[i] == '1' and binB[i] == '1':
			remainder = 1
		elif binA[i] == '1' and binB[i] == '0':
			remainder = 2
		final = (remainder + n) % 3
		if final == 0:
			xor = '0'
		elif final == 1:
			xor = '1'
		else:
			xor = '1'
		binAux += xor
	return int(binAux[2:], 2)
testCases = int(input())
for t in range(testCases):
	(a, b, n) = tuple(map(int, input().split(' ')))
	f = xorinacci(a, b, n)
	print(f)


t = int(input())
while t:
	(a, b, n) = map(int, input().split())
	mud = n % 3
	if mud == 1:
		print(b)
	elif mud == 2:
		print(a ^ b)
	elif mud == 0:
		print(a)
	t -= 1


T = int(input())
for _ in range(T):
	(a, b, n) = map(int, input().split())
	xor = 0
	if a >= b:
		aa = bin(a)[2:]
		bb = bin(b)[2:].zfill(len(aa))
	else:
		bb = bin(b)[2:]
		aa = bin(a)[2:].zfill(len(bb))
	for (i, (ia, ib)) in enumerate(zip(aa[::-1], bb[::-1])):
		if ia != ib:
			xor += 2 ** i
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(xor)


import os
count = int(input())
c = 0
res = list()
for i in range(0, count):
	(a, b, n) = map(int, input().split())
	res.append((a, b, a ^ b)[n % 3])
for i in range(0, len(res)):
	print(res[i])


import sys

def get_sn():
	return int(input())

def get_n():
	return map(int, input().split())

def get_ln():
	return list(get_n())

def solve():
	return 0

def main():
	t = get_sn()
	for _ in range(t):
		(a, b, n) = get_n()
		x = a ^ b
		result = [a, b, x]
		rem = n % 3
		print(result[rem])
main()


for t in range(int(input())):
	(a, b, n) = [int(j) for j in input().split()]
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)


num = int(input())
i = 0
while i < num:
	x = [int(x) for x in input().split()]
	z = x[2] % 3
	if z == 0:
		print(x[0])
	elif z == 1:
		print(x[1])
	else:
		print(x[0] ^ x[1])
	i = i + 1


test = int(input())
while test > 0:
	test -= 1
	(a, b, d) = map(int, input().split())
	c = a ^ b
	if d % 3 == 0:
		print(a)
	elif d % 3 == 1:
		print(b)
	else:
		print(c)


def solve(a, b, n):
	if n == 0:
		return a
	if n == 1:
		return b
	res = 0
	for i in range(32):
		x = a & 1 << i
		y = b & 1 << i
		if x:
			if y:
				res |= (n % 3 != 2) << i
			else:
				res |= (n % 3 != 1) << i
		elif y:
			res |= (n % 3 != 0) << i
	return res

def do():
	n = int(input())
	for _ in range(n):
		(a, b, n) = map(int, input().split(' '))
		print(solve(a, b, n))
do()


for i in range(int(input())):
	a = [int(i) for i in input().split()]
	l = a[0]
	r = a[1]
	p = a[0] ^ a[1]
	if a[2] % 3 == 0:
		print(l)
	elif a[2] % 3 == 1:
		print(r)
	else:
		print(p)


def XOR(c):
	if c % 3 == 0:
		return a
	elif c % 3 == 1:
		return b
	else:
		return a ^ b
T = int(input())
for i in range(T):
	(a, b, n) = map(int, input().split())
	print(XOR(n))


def flip_binary(n):
	s = bin(n)[2:]
	news = ''
	for i in s:
		if i == '0':
			news += '1'
		else:
			news += '0'
	return int(news, 2)
for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	c = a ^ b
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	else:
		n = n % 3
		if n == 2:
			print(c)
		elif n == 0:
			print(a)
		else:
			print(b)


t = int(input().strip())
while t != 0:
	t -= 1
	(a, b, n) = map(int, input().strip().split(' '))
	n %= 3
	ls = [a, b, a ^ b]
	print(ls[n])


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	a = bin(a)[2:]
	b = bin(b)[2:]
	s = ''
	al = len(a)
	bl = len(b)
	if al > bl:
		b = '0' * (al - bl) + b
	else:
		a = '0' * (bl - al) + a
	m = max(al, bl)
	d = n % 3
	if d == 0:
		for k in range(m):
			s = s + a[k]
	if d == 1:
		for k in range(m):
			s = s + b[k]
	if d == 2:
		for k in range(m):
			s = s + str((int(a[k]) + int(b[k])) % 2)
	print(int(s, 2))


T = int(input())
for i in range(T):
	(a, b, n) = (int(j) for j in input().split())
	f = [a, b, a ^ b]
	print(f[n % 3])


N = int(input())
for i in range(N):
	(a, b, n) = list(map(int, input().split(' ')))
	ans = [a, b, a ^ b]
	print(ans[int(n) % 3])


s = int(input())
for _ in range(s):
	(a, b, n) = map(int, input().split())
	g = [a, b, a ^ b]
	print(g[n % 3])


t = int(input())
while t:
	(a, b, c) = map(int, input().rstrip().split(' '))
	if c % 3 == 0:
		print(a)
	elif c % 3 == 1:
		print(b)
	else:
		print(a ^ b)
	t -= 1


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	while k >= 3:
		k = k % 3
	if k == 0:
		print(n)
	elif k == 1:
		print(m)
	elif k == 2:
		print(n ^ m)


def xorfib(a, b, n):
	n = n % 3
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	else:
		print(a ^ b)
t = int(input())
for i in range(t):
	(a, b, n) = input().split()
	a = int(a)
	b = int(b)
	n = int(n)
	xorfib(a, b, n)


t = int(input())
for _ in range(t):
	(a, b, k) = map(int, input().split())
	l = [a, b, a ^ b]
	print(l[k % 3])


T = input()
for times in range(int(T)):
	(a, b, n) = input().split()
	n = int(n)
	a = int(a)
	b = int(b)
	c = a ^ b
	yu = n % 3
	if yu == 0:
		print(a)
	if yu == 1:
		print(b)
	if yu == 2:
		print(c)


p = int(input())
for q in range(p):
	(a, b, n) = map(int, input().split())
	if n % 3 == 1:
		print(b)
	elif n % 3 == 2:
		print(a ^ b)
	else:
		print(a)


for t in range(int(input())):
	(a, b, n) = map(int, input().split())
	s = a ^ b
	if (n + 1) % 3 == 0:
		print(s)
	elif (n + 1) % 3 == 1:
		print(a)
	elif (n + 1) % 3 == 2:
		print(b)


def XORinacci_Naive(a, b, n):
	ans = 0
	if n == 0:
		ans = a
	elif n == 1:
		ans = b
	else:
		for i in range(n - 1):
			ans = a ^ b
			a = b
			b = ans
	return ans

def solve(a, b, n):
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)
t = int(input())
for _ in range(t):
	(a, b, n) = map(int, input().split())
	solve(a, b, n)


import operator
t = int(input())
for i in range(t):
	(a, b, n) = list(map(int, input().split()))
	x = operator.xor(a, b)
	m = [a, b, x]
	print(m[n % 3])


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	(a, b, n) = map(int, stdin.readline().rstrip().split(' '))
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	else:
		print([a, b, a ^ b][n % 3])


from operator import xor
t = int(input())
(a, b, n) = (0, 0, 0)
for i in range(t):
	(a, b, n) = map(int, input().split())
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	else:
		c = [a, b, xor(a, b)]
		t = int(n % 3)
		print(c[t])


t = int(input())
for qury in range(t):
	A = [0] * 3
	(A[0], A[1], n) = list(map(int, input().split()))
	A[2] = A[0] ^ A[1]
	print(A[n % 3])


from collections import defaultdict as dc
import sys
import math

def inp():
	p = sys.stdin.readline()
	return p
for _ in range(int(inp())):
	(a, b, n) = list(map(int, inp().split()))
	k = n % 3
	if k == 0:
		print(a)
	elif k == 1:
		print(b)
	elif k == 2:
		print(a ^ b)


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	arr = [a, b]
	arr.append(a ^ b)
	print(arr[n % 3])


import copy
num = int(input())
for i in range(0, num):
	(a, b, n) = [int(v) for v in input().split()]
	if n % 3 == 2:
		print(a ^ b)
	elif n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)


T = int(input())
for i in range(T):
	(a, b, n) = map(int, input().split())
	x = a ^ b
	d = {2: x, 0: a, 1: b}
	print(d[n % 3])


from math import *
from sys import *
from collections import defaultdict
M = 10 ** 9 + 7

def pow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def powmod(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a *= a
		b >>= 1
	return res

def inv(a, m):
	return powmod(a, m - 2, m)

def factor(n):
	potentional_p = 3
	itog_list = {}
	if n % 2 == 0:
		itog_list[2] = 0
	while n % 2 == 0:
		n = n // 2
		itog_list[2] += 1
	while n - 1:
		if potentional_p > n ** 0.5:
			if n in itog_list:
				itog_list[n] += 1
			else:
				itog_list[n] = 1
			return itog_list
		while n % potentional_p == 0:
			n = n // potentional_p
			if potentional_p in itog_list:
				itog_list[potentional_p] += 1
			else:
				itog_list[potentional_p] = 1
		potentional_p += 2
	return itog_list
t = int(stdin.readline())
for _ in range(t):
	(a, b, n) = list(map(int, stdin.readline().split()))
	n %= 3
	if n == 0:
		print(a)
	if n == 1:
		print(b)
	if n == 2:
		print(a ^ b)


def xor(a, b):
	ans = ''
	ma = a if len(a) > len(b) else b
	mi = a if len(a) < len(b) else b
	for d in range(1, len(mi) - 1):
		ans = '1' + ans if a[-d] != b[-d] else '0' + ans
	ans = ma[2:2 + len(ma) - len(mi)] + ans
	return '0b' + ans

def f(a, b, n):
	if n == 0:
		return a
	if n == 1:
		return b
	return xor(f(a, b, n - 1), f(a, b, n - 2))
arr = []
for i in range(int(input())):
	p = input().split()
	(x, y) = (bin(int(p[0])), bin(int(p[1])))
	z = int(p[2]) % 3
	arr.append(int(f(x, y, z), 2))
print(*arr, sep='\n')


for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	(a, b) = (bin(a)[2:], bin(b)[2:])
	m = max(len(a), len(b))
	a = '0' * (m - len(a)) + a
	b = '0' * (m - len(b)) + b
	res = ''
	if n == 0:
		res = a
	elif n == 1:
		res = b
	else:
		for i in range(m):
			r = a[i] + b[i]
			if r == '00':
				res += '0'
			else:
				k = (n - (int(r, 2) - 1)) % 3
				res += '011'[k]
	print(int(res, 2))


T = int(input())
start = []
for _ in range(T):
	start.append(list(map(int, input().strip().split())))
for i in range(T):
	a = start[i][0]
	b = start[i][1]
	n = start[i][2]
	val = [a, b, a ^ b][n % 3]
	print(val, end='\n')


import sys
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')
input = lambda : sys.stdin.readline()

def solve():
	T = int(input())
	for _ in range(T):
		(a, b, n) = map(int, input().split())
		x = [a, b, a ^ b]
		n = n % 3
		print(x[n])
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
solve()


T = int(input())
large = []
for i in range(0, T):
	list1 = []
	l = ''
	str1 = input() + ' '
	for element in str1:
		if element != ' ':
			l = l + element
		else:
			list1.append(int(l))
			l = ''
	(list1[0], list1[2]) = (list1[2], list1[0])
	(list1[1], list1[2]) = (list1[2], list1[1])
	count = list1[0] % 3
	list1.append(list1[1] ^ list1[2])
	large.append(list1[count + 1])
for element in large:
	print(element)


t = int(input())
res = []
for x in range(t):
	(a, b, n) = [int(x) for x in input().split()]
	f = []
	f.append(a)
	f.append(b)
	f.append(a ^ b)
	res.append(f[n % 3])
for x in res:
	print(x)


t = int(input())
for nt in range(t):
	(a, b, n) = map(int, input().split())
	c = a ^ b
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(c)


t = int(input())
for i in range(t):
	abn = input().split()
	a = int(abn[0])
	b = int(abn[1])
	n = int(abn[2])
	answer = [a, b]
	answer += [a ^ b]
	n = n % 3
	print(answer[n])


for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	f = [a, b]
	f.append(f[0] ^ f[1])
	print(f[n % 3])


T = int(input())
for case in range(T):
	(a, b, n) = map(int, input().split())
	x = [a, b, a ^ b]
	print(x[n % 3])


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	c = a ^ b
	A = [a, b, c]
	print(A[n % 3])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return input()

def iinp():
	return int(input())

def nninp():
	return map(int, input().split())

def llinp():
	return list(map(int, input().split()))

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
for __ in range(iinp()):
	(a, b, n) = nninp()
	c = a ^ b
	if n % 3 == 0:
		p(a)
	elif n % 3 == 1:
		p(b)
	else:
		p(c)


from sys import stdin

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
for _ in range(ii()):
	(a, b, n) = mi()
	print([a, b, a ^ b][n % 3])


import sys
from collections import defaultdict
input = lambda : sys.stdin.readline().rstrip()
for t in range(int(input())):
	(a, b, n) = input().split()
	(a, b) = (bin(int(a))[2:], bin(int(b))[2:])
	n = int(n)
	n += 1
	m = max(len(a), len(b))
	ans = ''
	for (i, j) in zip(a.zfill(m), b.zfill(m)):
		if i == j == '0':
			ans += '0'
		elif i == '0' and j == '1':
			ans += '101'[n % 3]
		elif i == '1' and j == '0':
			ans += '110'[n % 3]
		else:
			ans += '011'[n % 3]
	if n == 1:
		print(int(a, 2))
	elif n == 2:
		print(int(b, 2))
	else:
		print(int(ans, 2))


t = int(input())
for _ in range(t):
	(a, b, n) = list(map(int, input().split()))
	ans = a ^ b
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	elif n % 3 == 2:
		print(ans)
	elif n % 3 == 0:
		print(a)
	else:
		print(b)


t = int(input())
for i in range(1, t + 1, 1):
	(a, b, c) = map(int, input().split())
	if c % 3 == 0:
		print(a)
	if c % 3 == 1:
		print(b)
	if c % 3 == 2:
		print(a ^ b)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	(a, b, n) = mp()
	ml = [a, b, a ^ b]
	print(ml[n % 3])


for _ in range(int(input())):
	(a, b, n) = [int(x) for x in input().split()]
	arr = [a, b, a ^ b]
	print(arr[n % 3])


def f(a, b, n):
	r = [a, b, a ^ b]
	return r[n % 3]
n = int(input())
re = []
for i in range(0, n):
	(a, b, n) = list(map(int, input().split()))
	re.append(f(a, b, n))
for i in re:
	print(i)


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	(l, n) = (l[0:2], l[2])
	x = l[-2] ^ l[-1]
	l.append(x)
	print(l[n % 3])


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
t = rint()
for _ in range(t):
	(a, b, n) = rints()
	print([a, b, a ^ b][n % 3])


try:
	t = int(input())
	for i in range(t):
		(a, b, n) = map(int, input().split())
		c = [a, b, a ^ b]
		print(c[n % 3])
except:
	pass


read = lambda : map(int, input().split())
T = int(input())
for i in range(T):
	(a, b, n) = read()
	f = [0] * 5
	f[0] = a
	f[1] = b
	f[2] = a ^ b
	print(f[n % 3])


t = int(input())
a = []
crnt = ''
if t == 0:
	print(0)
else:
	for i in range(0, t):
		b = []
		s = input()
		if s[-1] != ' ':
			s += ' '
		crnt = ''
		for j in range(0, len(s)):
			if s[j] == ' ':
				b += [int(crnt)]
				crnt = ''
				continue
			crnt += s[j]
		a.append(b)
for i in range(0, t):
	if a[i][2] % 3 == 0:
		print(a[i][0])
	if a[i][2] % 3 == 1:
		print(a[i][1])
	if a[i][2] % 3 == 2:
		print(a[i][0] ^ a[i][1])


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	arr = [a, b, a ^ b]
	print(arr[n % 3])


GI = lambda : int(input())
GIS = lambda : map(int, input().split())
LGIS = lambda : list(GIS())

def main():
	for t in range(GI()):
		(a, b, n) = GIS()
		c = a ^ b
		print((a, b, c)[n % 3])
main()


n = int(input())
for i in range(n):
	(a, b, lenr) = map(int, input().split())
	se = set()
	se.add((b, a))
	ans = [a, b]
	while (ans[-1] ^ ans[-2], ans[-1]) not in se:
		ans.append(ans[-1] ^ ans[-2])
		se.add((ans[-1] ^ ans[-2], ans[-1]))
	t = lenr % len(ans)
	print(ans[t])


def process():
	(a, b, c) = input().split()
	(a, b, c) = (int(a), int(b), int(c))
	tmp = a ^ b
	c %= 3
	if c == 0:
		print(a)
	if c == 1:
		print(b)
	if c == 2:
		print(tmp)
n = int(input())
for i in range(n):
	process()


import sys

def read_input():
	lines = sys.stdin.readlines()
	lines = [line.rstrip() for line in lines]
	lines = lines[1:]
	lines = [tuple(map(int, line.split())) for line in lines]
	return lines
input = read_input()

def xorinacci(a, b, n):
	if n == 0:
		return a
	if n == 1:
		return b
	if n == 2:
		return a ^ b
	return xorinacci(a, b, n % 3)

def main():
	for (a, b, n) in input:
		print(xorinacci(a, b, n))
main()


from sys import stdin
t = int(stdin.readline().strip())
for i in range(t):
	(a, b, n) = map(int, stdin.readline().strip().split())
	x = a ^ b
	arr = [a, b, x]
	n = n % 3
	print(arr[n])


for _ in range(int(input())):
	a = list(map(int, input().split()))
	n = a[2]
	a[2] = a[0] ^ a[1]
	print(a[n % 3])


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(a, b, n) = LI()
		r = [a, b, a ^ b]
		rr.append(r[n % 3])
	return JA(rr, '\n')
print(main())


t = int(input())
s = []
for ijj in range(0, t):
	x = input().split()
	if int(x[2]) < 2:
		if int(x[2]) == 0:
			s.append(x[0])
		else:
			s.append(x[1])
	else:
		a = list(bin(int(x[0])))
		b = list(bin(int(x[1])))
		n = int(x[2])
		del a[0]
		del a[0]
		del b[0]
		del b[0]
		if len(b) > len(a):
			h = len(b) - len(a)
			a.reverse()
			for i in range(0, h):
				a.append('0')
			a.reverse()
		if len(a) > len(b):
			h = len(a) - len(b)
			b.reverse()
			for i in range(0, h):
				b.append('0')
			b.reverse()
		n -= 1
		m = n % 3
		y = []
		for i in range(0, len(b)):
			if a[i] == b[i] == '1':
				if m == 0:
					y.append(1)
				elif m == 2:
					y.append(1)
				else:
					y.append(0)
			elif a[i] == b[i] == '0':
				y.append(0)
			elif a[i] == '1' and b[i] == '0':
				if m == 0:
					y.append(0)
				elif m == 2:
					y.append(1)
				else:
					y.append(1)
			elif m == 0:
				y.append(1)
			elif m == 2:
				y.append(0)
			else:
				y.append(1)
		g = 0
		for i in y:
			g = g * 2 + i
		s.append(g)
for i in s:
	print(i)


def xorbanachi(a, b, k):
	k = k % 3
	for i in range(k):
		(a, b) = (b, a ^ b)
	print(a)
for i in range(int(input())):
	(a, b, k) = map(int, input().split())
	xorbanachi(a, b, k)


t = int(input())
for e in range(t):
	(a, b, n) = map(int, input().split())
	an = [a, b, a ^ b]
	print(an[n % 3])


a = int(input())
for i in range(a):
	(k, l, m) = map(int, input().split())
	print([k, l, k ^ l][m % 3])


from sys import stdin, stdout
from collections import defaultdict
from collections import deque
import math
import copy
T = int(input())
for i in range(T):
	(A, B, N) = [int(x) for x in stdin.readline().split()]
	if N == 0:
		print(A)
	elif N == 1:
		print(B)
	else:
		(u, v) = (B, A)
		N = (N - 2) % 3 + 1
		for i in range(N):
			s = u ^ v
			(u, v) = (s, u)
		print(s)


def solve(a, b, n):
	if n == 0:
		return a
	if n == 1:
		return b
	if n == 2:
		return a ^ b
	else:
		return solve(a, b, n % 3)
t = int(input())
for i in range(t):
	s = list(map(int, input().split()))
	ans = solve(s[0], s[1], s[2])
	print(ans)


T = int(input())
for _ in range(T):
	(a, b, n) = map(int, input().split())
	res = [a, b, a ^ b]
	print(res[n % 3])


CASES = int(input())
for i in range(CASES):
	(a, b, n) = map(int, input().split())
	xor = a ^ b
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(xor)


def fib(last, first, second):
	if last == 0:
		return first
	if last == 1:
		return second
	if last == 2:
		return first ^ second
	return fib(last % 3, first, second)
numbers = int(input())
for i in range(numbers):
	input2 = [int(i) for i in input().split()]
	print(fib(input2[2], input2[0], input2[1]))


t = int(input())
for _ in range(t):
	ls = [int(x) for x in input().split()]
	ls[2] = ls[2] % 3
	if ls[2] == 1:
		print(ls[1])
	elif ls[2] == 0:
		for count in range(2):
			(ls[1], ls[0]) = (ls[0] ^ ls[1], ls[1])
		print(ls[1])
	else:
		print(ls[1] ^ ls[0])


def sol3(a, b, n):
	n1 = a
	n2 = b
	n3 = a ^ b
	x = n % 3
	if x == 0:
		return n1
	elif x == 1:
		return n2
	elif x == 2:
		return n3
t = int(input())
for _ in range(t):
	(a, b, n) = map(int, input().split())
	print(sol3(a, b, n))


for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	n = int(n % 3)
	array = [a, b]
	for i in range(2, n + 1):
		fibo = array[i - 2] ^ array[i - 1]
		array.append(fibo)
	print(array[n])


for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	if n == 0:
		print(a)
		continue
	if n == 1:
		print(b)
		continue
	c = a ^ b
	l = [a, b, c]
	print(l[n % 3])


q = int(input())
for re in range(q):
	(a, b, n) = map(int, input().split())
	if n % 3 == 2:
		print(a ^ b)
	if n % 3 == 0:
		print(a)
	if n % 3 == 1:
		print(b)


from math import ceil
for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	if c % 3 == 0:
		print(a)
	elif c % 3 == 1:
		print(b)
	else:
		print(a ^ b)


t = int(input())
for i in range(t):
	(a, b, n) = [int(i) for i in input().split()]
	li = [a, b, a ^ b]
	print(li[n % 3])


t = int(input())
for j in range(t):
	(a, b, n) = [int(i) for i in input().split()]
	if n % 3 == 0:
		print(a)
	if n % 3 == 1:
		print(b)
	if n % 3 == 2:
		print(a ^ b)


a = int(input())
for i in range(a):
	(a1, a2, n) = list(map(int, input().split()))
	a3 = a1 ^ a2
	n1 = [a1, a2, a3]
	print(n1[n % 3])


T = int(input())
while T > 0:
	T -= 1
	(a, b, n) = [int(x) for x in input().split()]
	d = [a, b, a ^ b]
	print(d[n % 3])


import functools

@functools.lru_cache(maxsize=None)
def fib(n):
	global a, b
	if n == 0:
		return a
	if n == 1:
		return b
	return fib(n - 1) ^ fib(n - 2)
for _ in range(int(input())):
	l = [int(x) for x in input().split()]
	a = l[0]
	b = l[1]
	n = l[2]
	print(fib(n % 3))
	fib.cache_clear()


T = int(input())
for t in range(T):
	(a, b, n) = map(int, input().strip().split())
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)


for i in range(int(input())):
	(a, b, n) = input().split()
	a = int(a)
	b = int(b)
	n = int(n)
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	elif n % 3 == 2:
		print(a ^ b)


from bisect import *
from collections import *
from itertools import *
import functools
import sys
from math import *
from decimal import *
from copy import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b):
	return abs(a[0] - b[0]) + abs(b[1] - a[1])

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def eld(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	st = en = be = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
			st = be
			en = i
		if meh < 0:
			meh = 0
			be = i + 1
	return (msf, st, en)

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()

def fac(n):
	ans = 1
	for i in range(1, n + 1):
		ans *= i
		ans %= MOD
	return ans
for _ in range(int(input())):
	(a, b, n) = arrIN()
	n += 1
	if n % 3 == 0:
		print(a ^ b)
	elif n % 3 == 1:
		print(a)
	else:
		print(b)


q = int(input())
for _ in range(q):
	(a, b, n) = map(int, input().split())
	f = {}
	f[0] = a
	f[1] = b
	f[2] = a ^ b
	print(f[n % 3])


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	n = n % 3
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	else:
		a = bin(a)[2:]
		b = bin(b)[2:]
		sum = 0
		for i in range(0, min(len(a), len(b))):
			if a[len(a) - i - 1] != b[len(b) - i - 1]:
				sum = sum + pow(2, i)
		for i in range(min(len(a), len(b)), max(len(a), len(b))):
			if len(a) > len(b):
				if a[len(a) - 1 - i] == '1':
					sum = sum + pow(2, i)
				continue
			if b[len(b) - 1 - i] == '1':
				sum = sum + pow(2, i)
		print(sum)


def input_ints():
	return list(map(int, input().split()))

def output_list(v):
	print(' '.join((str(x) for x in v)))

def main():
	t = int(input())
	for _ in range(t):
		(a, b, n) = input_ints()
		print([a, b, a ^ b][n % 3])
main()


T = int(input())
for i in range(T):
	abn = input().split()
	a = int(abn[0])
	b = int(abn[1])
	n = int(abn[2])
	c = a ^ b
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(c)


n = int(input())
for i in range(n):
	(a, b, n) = [int(r) for r in input().split()]
	f = [a, b, a ^ b]
	print(f[n % 3])


t = int(input())
for te in range(0, t):
	(a, b, n) = [int(x) for x in input().split()]
	c = a ^ b
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(c)


tCase = int(input())
for i in range(tCase):
	(a, b, n) = [x for x in input().split()]
	(a, b, n) = (int(a), int(b), int(n))
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)


t = int(input())
for _ in range(t):
	(a, b, n) = map(int, input().split(' '))
	d = {1: a, 2: b, 0: a ^ b}
	print(d[(n + 1) % 3])


t = int(input())
for _ in range(t):
	(a, b, n) = map(int, input().split())
	abin = list(format(a, '064b'))
	bbin = list(format(b, '064b'))
	if n == 0:
		print(a)
		continue
	if n == 1:
		print(b)
		continue
	cbin = list()
	for i in range(64):
		if abin[i] == '0' and bbin[i] == '0':
			cbin.append('0')
		elif abin[i] == '1' and bbin[i] == '1':
			cbin.append(['1', '1', '0'][n % 3])
		elif abin[i] == '1' and bbin[i] == '0':
			cbin.append(['1', '0', '1'][n % 3])
		else:
			cbin.append(['0', '1', '1'][n % 3])
	print(int(''.join(cbin), base=2))


def XORinacci(a, b, n):
	if n == 0:
		return a
	if n == 1:
		return b
	if n == 2:
		return a ^ b
	return XORinacci(a, b, n % 3)
x = []
p = int(input())
for i in range(p):
	y = input()
	l = y.split()
	a = int(l[0])
	b = int(l[1])
	n = int(l[2])
	x.append(XORinacci(a, b, n))
for i in x:
	print(i)


from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
while t:
	t -= 1
	(a, b, n) = map(int, input().split())
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	print([a, b][c % 3] if c % 3 < 2 else str(a ^ b))


for _ in range(int(input())):
	(a, b, n) = list(map(int, input().split()))
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	elif n == 2:
		print(a ^ b)
	else:
		x = [0] * 4
		x[0] = a
		x[1] = b
		x[2] = a ^ b
		print(x[n % 3])


class cinn:

	def __init__(self):
		self.x = []

	def cin(self, t=int):
		if len(self.x) == 0:
			a = input()
			self.x = a.split()
			self.x.reverse()
		return self.get(t)

	def get(self, t):
		return t(self.x.pop())

	def clist(self, n, t=int):
		l = [0] * n
		for i in range(n):
			l[i] = self.cin(t)
		return l

	def clist2(self, n, t1=int, t2=int, t3=int, tn=2):
		l = [0] * n
		for i in range(n):
			if tn == 2:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				l[i] = (a1, a2)
			elif tn == 3:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				a3 = self.cin(t3)
				l[i] = (a1, a2, a3)
		return l

	def clist3(self, n, t1=int, t2=int, t3=int):
		return self.clist2(self, n, t1, t2, t3, 3)

	def cout(self, i, ans=''):
		if ans == '':
			print('Case #' + str(i + 1) + ':', end=' ')
		else:
			print('Case #' + str(i + 1) + ':', ans)

	def printf(self, thing):
		print(thing, end='')

	def countlist(self, l, s=0, e=None):
		if e == None:
			e = len(l)
		dic = {}
		for el in range(s, e):
			if l[el] not in dic:
				dic[l[el]] = 1
			else:
				dic[l[el]] += 1
		return dic

	def talk(self, x):
		print(x, flush=True)

	def dp1(self, k):
		L = [-1] * k
		return L

	def dp2(self, k, kk):
		L = [-1] * k
		for i in range(k):
			L[i] = [-1] * kk
		return L

	def isprime(self, n):
		if n == 1 or n == 0:
			return False
		for i in range(2, int(n ** 0.5 + 1)):
			if n % i == 0:
				return False
		return True

	def factors(self, n):
		from functools import reduce
		return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

	def nthprime(self, n):
		i = 0
		s = 2
		L = []
		while i < n:
			while not self.isprime(s):
				s += 1
			L.append(s)
			s += 1
			i += 1
		return L

	def matrixin(self, m, n, t=int):
		L = []
		for i in range(m):
			p = self.clist(n, t)
			L.append(p)
		return L

	def seive(self, k):
		n = k + 1
		L = [True] * n
		L[1] = False
		L[0] = False
		for i in range(2, n):
			if L[i] == True:
				for j in range(2 * i, n, i):
					L[j] = False
		return L

	def seiven(self, n, L):
		i = 0
		for j in range(len(L)):
			if L[j] == True:
				i += 1
			if i == n:
				return j

	def matrixin2(self, m, t=int):
		L = []
		for i in range(m):
			iny = self.cin(str)
			lsmall = []
			for el in iny:
				lsmall.append(t(el))
			L.append(lsmall)
		return L
c = cinn()
n = c.cin()
for i in range(n):
	a = c.cin()
	b = c.cin()
	e = c.cin()
	k = a ^ b
	if e % 3 == 2:
		print(k)
	elif e % 3 == 0:
		print(a)
	elif e % 3 == 1:
		print(b)


for z in range(int(input())):
	(last1, last2, n) = map(int, input().split())
	if n % 3 == 0:
		print(last1)
	elif n % 3 == 1:
		print(last2)
	else:
		print(last1 ^ last2)


t = int(input())
for _ in range(t):
	(a, b, n) = map(int, input().split())
	pow2 = 1
	res = 0
	while a > 0 or b > 0:
		a_sign = a % 2
		b_sign = b % 2
		a //= 2
		b //= 2
		if n == 0:
			res += pow2 * a_sign
		elif n == 1:
			res += pow2 * b_sign
		elif a_sign == 0 and b_sign == 1:
			if (n - 2) % 3 == 0 or (n - 2) % 3 == 2:
				res += pow2
		elif a_sign == 0 and b_sign == 0:
			res += 0
		elif a_sign == 1 and b_sign == 0:
			if (n - 2) % 3 <= 1:
				res += pow2
		elif a_sign == 1 and b_sign == 1:
			if (n - 2) % 3 >= 1:
				res += pow2
		pow2 *= 2
	print(res)


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())

	def fib(n):
		n = n % 3
		if n == 0:
			return a
		if n == 1:
			return b
		else:
			return fib(n - 1) ^ fib(n - 2)
	x = fib(n)
	print(x)


T = int(input())
for i in range(T):
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	n = int(s[2])
	results = {0: a, 1: b, 2: a ^ b}
	print(results[n % 3])


test_cases = input()
for i in range(int(test_cases)):
	a = input()
	b = []
	b = a.split()
	for x in range(3):
		b[x] = int(b[x])
	if int(b[2]) == 0 or int(b[2]) % 3 == 0:
		y = int(b[0])
	elif int(b[2]) == 1 or int(b[2]) % 3 == 1:
		y = int(b[1])
	else:
		y = int(b[0] ^ b[1])
	print(y)


def f(l):
	(a, b, n) = l
	l[2] = a ^ b
	return l[n % 3]
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	print(f(l))


gi = lambda : list(map(int, input().split()))
for k in range(gi()[0]):
	(a, b, n) = gi()
	l = [a, b, a ^ b]
	print(l[n % 3])


res = []
t = input()
for i in range(int(t)):
	linea = input()
	linea = linea.split(' ')
	a = int(linea[0])
	b = int(linea[1])
	n = int(linea[2])
	if n > 1:
		c = a ^ b
		xor = [b, c, a]
		sig = n - (n - 1) // 3 * 3
		res.append(xor[sig - 1])
	elif n == 1:
		res.append(b)
	else:
		res.append(a)
for r in res:
	print(r)


def f(a, b, n):
	if n % 3 == 0:
		return a
	elif n % 3 == 1:
		return b
	else:
		return a ^ b
n = int(input())
M = []
for i in range(n):
	L = [int(i) for i in input().split()]
	M.append(L)
for i in range(n):
	L = M[i]
	print(f(L[0], L[1], L[2]))


test = int(input())
temp = [list(map(int, input().split())) for x in range(test)]
for item in temp:
	if item[-1] % 3 == 0:
		print(item[0])
	elif item[-1] % 3 == 1:
		print(item[1])
	else:
		print(item[0] ^ item[1])


def fibonacci(a, b, n):
	if n < 0:
		print('Incorrect input')
	elif n == 0:
		return a
	elif n == 1:
		return b
	elif n == 2:
		return a ^ b
	else:
		for i in range(b, n):
			c = a ^ b
			a = b
			b = c
		return b
n = int(input())
for i in range(0, n):
	(a, b, n) = map(int, input().split(' '))
	c = a ^ b
	if b ^ c == a:
		t = n % 3
		if t == 0:
			print(a)
		elif t == 1:
			print(b)
		elif t == 2:
			print(c)
	else:
		print(fibonacci(a, b, n))


def main():
	T = int(input())
	for _ in range(T):
		(a, b, n) = list(map(int, input().split()))
		ans = [a, b, a ^ b]
		print(ans[n % 3])
main()


t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	num = [a, b, a ^ b]
	print(num[n % 3])


import math, sys
from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
n = int(input())
for i in range(0, n):
	(a, b, n) = li()
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)


k = int(input())
for o in range(k):
	(a, b, n) = [int(x) for x in input().split()]
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	elif n % 3 == 2:
		print(a ^ b)


from operator import xor

def xorfib(a, b, n):
	res = [a, b, xor(a, b)]
	return res[n % 3]
q = int(input())
for _ in range(q):
	(a, b, n) = map(int, input().split())
	print(xorfib(a, b, n))


T = int(input())
for t in range(T):
	(a, b, n) = [int(x) for x in input().split()]
	k = 0
	x = 0
	while a > 0 or b > 0:
		if a % 2 == 0 and b % 2 == 1 and (n % 3 != 0) or (a % 2 == 1 and b % 2 == 0 and (n % 3 != 1)) or (a % 2 == 1 and b % 2 == 1 and (n % 3 != 2)):
			x += 2 ** k
		k = k + 1
		a = a // 2
		b = b // 2
	print(x)


t = int(input())
for x in range(t):
	l1 = [int(x) for x in input().split()]
	a = l1[0]
	b = l1[1]
	n = l1[2]
	for x in range((n - 1) % 3):
		temp = b
		b = a ^ b
		a = temp
	print(b)


t = int(input())
while t > 0:
	t -= 1
	(a, b, n) = input().split()
	n = int(n)
	a = int(a)
	b = int(b)
	s1 = a
	s2 = b
	if n % 3 == 0:
		s3 = s1
	elif n % 3 == 2:
		s3 = s1 ^ s2
	else:
		s3 = s2
	print(s3)


t = int(input())
for _ in range(t):
	(a, b, n) = list(map(int, input().split()))
	dp = [[] for _ in range(1001)]
	dp[0] = a
	dp[1] = b
	for i in range(2, 1001):
		dp[i] = dp[i - 1] ^ dp[i - 2]
	print(dp[n % 3])


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, sys.stdin.readline().split()))

def num():
	return map(int, sys.stdin.readline().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		(a, b, n) = num()
		n = n % 3
		if n == 0:
			print(a)
		if n == 1:
			print(b)
		if n == 2:
			print(a ^ b)
solve()


I0 = lambda : map(int, input().split())
I1 = lambda : int(input())
I2 = lambda : list(map(int, input().split()))
from math import ceil
for i in range(I1()):
	(a, b, n) = I0()
	f0 = a
	f1 = b
	if n == 0:
		print(a)
		continue
	if n == 1:
		print(b)
	else:
		yy = a ^ b
		if ceil((n - 2) / 3) == int((n - 2) / 3):
			print(yy)
		elif ceil((n - 3) / 3) == int((n - 3) / 3):
			print(a)
		else:
			print(b)


for x in range(int(input())):
	(a, b, c) = map(int, input().split())
	d = c % 3
	if d == 0:
		print(a)
	elif d == 1:
		print(b)
	else:
		print(a ^ b)


n = int(input())
for i in range(n):
	(a, b, k) = [int(item) for item in input().split()]
	if k % 3 == 0:
		print(a)
	elif k % 3 == 1:
		print(b)
	else:
		print(a ^ b)


for t in range(int(input())):
	(a, b, n) = map(int, input().split())
	d = [0] * 3
	if a == 0 and b == 0:
		print('0')
	else:
		d[0] = a
		if n > 0:
			d[1] = b
		if n == 0:
			print(d[0])
		elif n == 1:
			print(d[1])
		else:
			d[2] = d[0] ^ d[1]
			if n == 2:
				print(d[2])
			else:
				print(d[n % 3])


T = int(input())
for t in range(T):
	A = input().split()
	for i in range(len(A)):
		A[i] = int(A[i])
	c = A[0] ^ A[1]
	if A[2] % 3 == 0:
		print(A[0])
	elif A[2] % 3 == 1:
		print(A[1])
	else:
		print(c)


t = int(input())
325
arr = []
for _ in range(t):
	(a, b, n) = map(int, input().split(' '))
	c = a ^ b
	n = n % 3
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	elif n == 2:
		print(c)


for i in range(int(input())):
	(a, b, n) = map(int, input().split())
	print(a ^ b if n % 3 == 2 else b if n % 3 == 1 else a)


n = int(input())

def fibo(a, b, c):
	if c % 3 == 0:
		return a
	elif c % 3 == 1:
		return b
	else:
		return a ^ b
for i in range(n):
	l = list(map(int, input().split()))
	a = l[0]
	b = l[1]
	c = l[2]
	ans = a
	ans = fibo(a, b, c)
	print(ans)


for cas in range(int(input())):
	(x, y, z) = map(int, input().split())
	print([x, y, x ^ y][z % 3])


t = int(input())
while t > 0:
	(a, b, n) = map(int, input().split())
	s = list()
	s.append(a)
	s.append(b)
	s.append(a ^ b)
	print(s[n % 3])
	t = t - 1


for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	ans = [a, b]
	if n in [0, 1]:
		print(ans[n])
		continue
	elif a ^ b <= 2 ** len(bin(max(a, b))[2:]) - 1:
		ans.append(a ^ b)
		print(ans[n % 3])


T = int(input().strip())
mod = 1000000007
for t in range(T):
	(a, b, n) = [int(x) for x in input().strip().split(' ')]
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)


def xorinacci(n):
	if n == 0:
		return int(a)
	elif n == 1:
		return b
	else:
		return int(a ^ b)
t = int(input())
result = []
for i in range(0, t):
	(a, b, n) = map(int, input().split())
	res = xorinacci(n % 3)
	result.append(res)
for i in result:
	print(i)


input_list = list(map(int, input().split()))
for t in range(0, input_list[0]):
	case = list(map(int, input().split()))
	a = case[0]
	b = case[1]
	n = case[2]
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	elif a == b:
		if (n + 1) % 3 == 0:
			print(0)
		else:
			print(a)
	else:
		res = 0
		loop_size = 0
		sdic = [a, b]
		for i in range(2, n + 1):
			res = a ^ b
			if res == case[1] and b == case[0]:
				loop_size = i - 1
				break
			a = b
			b = res
			sdic.append(res)
		if loop_size == 0:
			print(sdic[n])
		else:
			print(sdic[n % loop_size])


import math as mt
import sys, string
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda : list(map(int, input().split()))

def printARR(arr):
	for e in arr:
		print(e, end=' ')
	print()

def main():
	(a, b, n) = M()
	if n % 3 == 0:
		print(a)
	if n % 3 == 1:
		print(b)
	if n % 3 == 2:
		print(a ^ b)
tc = 1
tc = I()
for _ in range(tc):
	main()


from math import gcd, ceil, log, log2
from collections import deque
from bisect import bisect_right, bisect_left
for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)


t = int(input())
while t > 0:
	(a, b, n) = [int(x) for x in input().split()]
	k = n % 3
	if k == 0:
		print(a)
	if k == 1:
		print(b)
	if k == 2:
		print(a ^ b)
	t -= 1


t = int(input())
for iteration in range(t):
	(a, b, n) = map(int, input().split())
	r = n % 3
	answer = a
	if r == 1:
		answer = b
	elif r == 2:
		answer = a ^ b
	print(answer)


def solve(a, b, n):
	if n % 3 == 2:
		return a ^ b
	elif n % 3 == 0:
		return a
	else:
		return b

def main():
	t = int(input())
	for _ in range(t):
		(a, b, n) = list(map(int, input().strip().split()))
		print(solve(a, b, n))
main()


from sys import stdin
input()
for i in stdin:
	(a, b, n) = map(int, i.split())
	c = b ^ a
	n += 1
	if not n % 3:
		print(c)
	elif n % 3 == 2:
		print(b)
	else:
		print(a)


mod = 1000000007
t = int(input())
for _ in range(t):
	(a, b, n) = map(int, input().split())
	c = a ^ b
	n = n % 3
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	else:
		print(c)


N = int(input())
for i in range(N):
	Data = list(map(int, input().split()))
	n = Data[2]
	if n < 2:
		print(Data[n])
	else:
		ans = ''
		num_a = str(bin(Data[0]))
		num_a = num_a[2:]
		num_b = str(bin(Data[1]))
		num_b = num_b[2:]
		M = max(len(num_a), len(num_b))
		for j in range(0, M):
			pa = len(num_a) - j - 1
			pb = len(num_b) - j - 1
			if pa < 0 or num_a[pa] == '0':
				if pb < 0 or num_b[pb] == '0':
					ans += '0'
				elif n % 3 == 2 or n % 3 == 1:
					ans += '1'
				else:
					ans += '0'
			if pa >= 0 and num_a[pa] == '1':
				if pb < 0 or num_b[pb] == '0':
					if n % 3 == 2 or n % 3 == 0:
						ans += '1'
					else:
						ans += '0'
				elif n % 3 == 0 or n % 3 == 1:
					ans += '1'
				else:
					ans += '0'
		tmp_ans = ''
		for i in range(len(ans) - 1, -1, -1):
			tmp_ans += ans[i]
		tmp_ans = int(tmp_ans, 2)
		print(tmp_ans)


for Test in range(int(input())):
	X = list(map(int, input().split()))
	if X[2] <= 1:
		print(X[0] if X[2] == 0 else X[1])
		continue
	Answer = [X[0], X[1], X[0] ^ X[1]]
	print(Answer[X[2] % 3])


t = int(input())
for it in range(t):
	(a, b, n) = map(int, input().split())
	A = [0] * 3
	A[0] = a
	A[1] = b
	A[2] = A[0] ^ A[1]
	print(A[n % 3])


t = int(input())
for i in range(t):
	(x, y, m) = [int(j) for j in input().split()]
	if m % 3 == 0:
		print(x)
	elif m % 3 == 1:
		print(y)
	else:
		print(x ^ y)


def func(a, b):
	s = ''
	s1 = ''
	while a > 0:
		s = str(a % 2) + s
		a = a // 2
	while b > 0:
		s1 = str(b % 2) + s1
		b = b // 2
	x = max(len(s), len(s1))
	if x == len(s):
		s1 = (x - len(s1)) * '0' + s1
	else:
		s = (x - len(s)) * '0' + s
	xor = ''
	for i in range(x):
		if s[i] == s1[i]:
			xor += '0'
		else:
			xor += '1'
	xor = xor[::-1]
	intXor = 0
	for i in range(len(xor)):
		intXor = intXor + int(xor[i]) * 2 ** i
	return intXor
list_of_solutions = []
x = int(input())
for i in range(x):
	(a, b, n) = tuple(map(int, input().split()))
	x = (n - 2) / 3
	y = (n - 3) / 3
	x = str(x)
	y = str(y)
	x = x[x.index('.') + 1:]
	y = y[y.index('.') + 1:]
	if x == '0' and n >= 2:
		list_of_solutions.append(func(a, b))
	elif n == 1:
		list_of_solutions.append(b)
	elif n == 0:
		list_of_solutions.append(a)
	elif y == '0':
		list_of_solutions.append(a)
	else:
		list_of_solutions.append(b)
for i in list_of_solutions:
	print(i)


def mi():
	return map(int, input().split())
from sys import stdin
for _ in range(int(input())):
	(a, b, n) = mi()
	t = [a, b, a ^ b]
	print(t[n % 3])


t = int(input())
for _ in range(0, t):
	(x, y, n) = map(int, input().split())
	a = [x, y, x ^ y]
	print(a[n % 3])


def iA():
	n = [int(x) for x in input().split()]
	return n

def iI():
	n = int(input())
	return n

def iS():
	n = input()
	return n

def iAA(numArrs):
	n = []
	for i in range(numArrs):
		m = iA()
		n.append(m)
	return n

def pA(arr):
	for i in range(len(arr)):
		print(arr[i], end=' ')
	print()
for i in range(iI()):
	r = iA()
	t = r[0] ^ r[1]
	if r[2] % 3 == 0:
		print(r[0])
	elif r[2] % 3 == 1:
		print(r[1])
	else:
		print(r[0] ^ r[1])


def printXOR(a, b, n):
	n = n - 1
	x = 0
	while n:
		x = a ^ b
		a = b
		b = x
		n -= 1
	print(x)
x = int(input())
for _ in range(x):
	(a, b, n) = map(int, input().split(' '))
	n = n % 3
	if n == 0:
		print(a)
	elif n == 1:
		print(b)
	else:
		printXOR(a, b, n)


for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	c = a ^ b
	lst = [a, b, c]
	print(lst[n % 3])


T = int(input())
while T > 0:
	(a, b, n) = map(int, input().split())
	if n % 3 == 0:
		ans = a
	elif n % 3 == 1:
		ans = b
	else:
		ans = a ^ b
	print(ans)
	T -= 1


for itr in range(int(input())):
	(a, b, n) = list(map(int, input().split()))
	ans = [a, b, a ^ b]
	print(ans[n % 3])


from sys import stdin, stdout
import bisect

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	(a, b, n) = mp()
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)
for _ in range(inp()):
	solve()


from sys import stdin
t = int(stdin.readline().rstrip())
for i in range(t):
	(a, b, n) = [int(x) for x in stdin.readline().rstrip().split()]
	(k, res) = (n % 3, a)
	if k is 1:
		res = b
	elif k is 2:
		res = a ^ b
	print(res)