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
Tags: Mathematics

Starter code:

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)


import operator
T = int(input())
for i in range(T):
	dic = {}
	ans = input().split(' ')
	dic[0] = int(ans[0])
	dic[1] = int(ans[1])
	dic[2] = int(operator.xor(dic[1], dic[0]))
	print(dic[int(ans[2]) % 3])


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


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


class TestCase:

	def __init__(self, a, b, n):
		self.a = a
		self.b = b
		self.n = n

	def solve(self):
		if self.n % 3 == 0:
			return self.a
		if self.n % 3 == 1:
			return self.b
		return self.a ^ self.b

class BundleOfTestsCases:

	def __init__(self, tests=None):
		self.tests = [] if not tests else tests

	def append(self, other):
		self.tests.append(other)

	def __iter__(self):
		for test in self.tests:
			yield test

	def __contains__(self, item):
		return item in self.tests

class Input:

	def __init__(self):
		self.NUMBER_OF_TESTS = int(input().strip())
		self.TESTS_CASES = BundleOfTestsCases()
		for i in range(self.NUMBER_OF_TESTS):
			line = input().strip().split(' ')
			line = list(map(int, line))
			t = TestCase(line[0], line[1], line[2])
			self.TESTS_CASES.append(t)

class Output:
	fibonaccis = []

	def print_output(self):
		for fib in self.fibonaccis:
			print(fib)

	def append(self, other):
		self.fibonaccis.append(other)

def main():
	input_values = Input()
	output_values = Output()
	for test in input_values.TESTS_CASES:
		output = test.solve()
		output_values.append(output)
	output_values.print_output()
main()


T = int(input())
while T > 0:
	list1 = [int(x) for x in input().split()]
	a = list1[0]
	b = list1[1]
	n = list1[2]
	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(a ^ b)
	T = T - 1


from sys import stdin, stdout
import heapq
import cProfile, math
from collections import Counter, defaultdict, deque
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
import sys
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
fac_warm_up = False
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n
		self.lista = [[_] for _ in range(n)]

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]
		self.lista[a] += self.lista[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

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

def prime_factors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

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

def fibonacci_modP(n, MOD):
	if n < 2:
		return 1
	return (cached_fn(fibonacci_modP, (n + 1) // 2, MOD) * cached_fn(fibonacci_modP, n // 2, MOD) + cached_fn(fibonacci_modP, (n - 1) // 2, MOD) * cached_fn(fibonacci_modP, (n - 2) // 2, MOD)) % MOD

def factorial_modP_Wilson(n, p):
	if p <= n:
		return 0
	res = p - 1
	for i in range(n + 1, p):
		res = res * cached_fn(InverseEuler, i, p) % p
	return res

def binary(n, digits=20):
	b = bin(n)[2:]
	b = '0' * (digits - len(b)) + b
	return b

def is_prime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

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

def warm_up_fac(MOD):
	global factorial_modP, fac_warm_up
	if fac_warm_up:
		return
	factorial_modP = [1 for _ in range(fac_warm_up_size + 1)]
	for i in range(2, fac_warm_up_size):
		factorial_modP[i] = factorial_modP[i - 1] * i % MOD
	fac_warm_up = True

def InverseEuler(n, MOD):
	return pow(n, MOD - 2, MOD)

def nCr(n, r, MOD):
	global fac_warm_up, factorial_modP
	if not fac_warm_up:
		warm_up_fac(MOD)
		fac_warm_up = True
	return factorial_modP[n] * (pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD) % MOD) % MOD

def test_print(*args):
	if testingMode:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def display_2D_list(li):
	for i in li:
		print(i)

def prefix_sum(li):
	sm = 0
	res = []
	for i in li:
		sm += i
		res.append(sm)
	return res

def get_int():
	return int(stdin.readline().strip())

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

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result

def ncr(n, r):
	return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

def binary_search(i, li):
	fn = lambda x: li[x] - x // i
	x = -1
	b = len(li)
	while b >= 1:
		while b + x < len(li) and fn(b + x) > 0:
			x += b
		b = b // 2
	return x
TestCases = True
fac_warm_up_size = 10 ** 5 + 100
optimise_for_recursion = False

def main():
	li = get_list()
	n = li[2]
	li[2] = li[0] ^ li[1]
	print(li[n % 3])
if TestCases:
	for i in range(get_int()):
		main()
else:
	main() if not optimise_for_recursion else threading.Thread(target=main).start()


import math

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


t = int(input())
while t:
	t = t - 1
	(a, b, c) = [int(x) for x in 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):
	l = list(map(int, input().split(' ')))
	if l[2] % 3 == 2:
		print(l[0] ^ l[1])
	elif l[2] % 3 == 0:
		print(l[0])
	else:
		print(l[1])


t = int(input())
while t > 0:
	t -= 1
	(a, b, n) = map(int, input().split())
	res = {0: a ^ b, 1: a, 2: b}
	print(res[(n + 1) % 3])


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
for _ in range(int(input())):
	(a, b, n) = mapin()
	if n % 3 == 2:
		print(a ^ b)
	elif n % 3 == 0:
		print(a)
	else:
		print(b)


def XORinacci(a, b, n):
	dp = [0] * 3
	dp[0] = a
	dp[1] = b
	dp[2] = a ^ b
	return dp[n % 3]
t = int(input())
while t:
	(a, b, n) = map(int, input().split())
	print(XORinacci(a, b, n))
	t = t - 1


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')


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


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


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
t = ii()
for j in range(t):
	(a, b, n) = mi()
	d = [a, b, a ^ b]
	print(d[n % 3])


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


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


q = int(input())
for i in range(q):
	(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 j in range(int(input())):
	(a, b, n) = map(int, input().split())
	f = [a, b, a ^ b]
	print(f[n % 3])


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter

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


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


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


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


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)


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


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])


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


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

def main():
	T = int(input())
	for _ in range(T):
		(a, b, n) = map(int, input().split())
		print(xorinacci(a, b, n))
	pass
import sys
input = sys.stdin.readline
main()


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)


T = int(input())
for k in range(T):
	(a, b, n) = map(int, input().split())
	(x, y) = (a, b)
	(z, i) = (0, 0)
	while not x == y == 0:
		if x % 2 != y % 2:
			z += 2 ** i
		(x, y) = (x // 2, y // 2)
		i += 1
	l = [a, b, z]
	u = n % 3
	print(l[u])


import sys
t = int(input())
while t > 0:
	(a, b, n) = map(int, sys.stdin.readline().split())
	fib = []
	fib.append(a)
	fib.append(b)
	fib.append(a ^ b)
	if n % 3 == 0:
		print(fib[0])
	elif n % 3 == 1:
		print(fib[1])
	else:
		print(fib[2])
	t -= 1


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


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))


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


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


import sys
input = lambda : sys.stdin.readline().strip()
T = int(input())
for i 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 fibo(a, b, n):
	fibs = [a, b]
	for i in range(2, n + 1):
		fibs.append((fibs[-1] | fibs[-2]) & (~fibs[-1] | ~fibs[-2]))
	return fibs[n]
for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	print(fibo(a, b, n % 3), end=' ')
	print()


def biton(num, idx):
	return 1 << idx & num > 0

def main():
	n = int(input())
	for i in range(n):
		(a, b, c) = [int(x) for x in input().split()]
		result = 0
		for i in range(64):
			if biton(a, i) and biton(b, i):
				if c % 3 != 2:
					result += 2 ** i
			elif biton(a, i) and (not biton(b, i)):
				if c % 3 != 1:
					result += 2 ** i
			elif not biton(a, i) and biton(b, i):
				if c % 3 != 0:
					result += 2 ** i
		print(result)
main()


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])


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


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)


n = int(input())
l = [[int(i) for i in input().split()] for i in range(n)]
for i in range(n):
	x = l[i][0] ^ l[i][1]
	m = l[i][2] % 3
	if m == 0:
		print(l[i][0])
	if m == 1:
		print(l[i][1])
	if m == 2:
		print(x)


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


def inp_n():
	return int(input())

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

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

def is_odd(n):
	if n & 1:
		return True
	return False
for _ in range(inp_n()):
	(a, b, n) = inp_mul_num()
	l = [0] * 3
	l[0] = a
	l[1] = b
	l[2] = a ^ b
	print(l[n % 3])


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


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


n = int(input())
for i in range(n):
	s = input().split(' ')
	(a, b, c) = (int(s[0]), int(s[1]), int(s[2]))
	print([a, b, a ^ b][c % 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 xor(a, b, n):
	c = 0
	y1 = a
	y2 = b
	x1 = ''
	x2 = ''
	x3 = ''
	f1 = True
	f2 = True
	while f1:
		x1 = str(a % 2) + x1
		a = int(a / 2)
		if a == 0:
			f1 = False
	while f2:
		x2 = str(b % 2) + x2
		b = int(b / 2)
		if b == 0:
			f2 = False
	d = len(x1) - len(x2)
	if d > 0:
		x2 = '0' * d + x2
	else:
		x1 = '0' * abs(d) + x1
	for k in range(len(x1)):
		if x1[k] == x2[k]:
			x3 = x3 + '0'
		else:
			x3 = x3 + '1'
	for l in range(len(x3)):
		c = int(x3[-(l + 1)]) * 2 ** l + c
	s = n % 3
	if s == 0:
		return y1
	elif s == 1:
		return y2
	else:
		return c
t = int(input())
for o in range(t):
	v = input().split()
	a = int(v[0])
	b = int(v[1])
	n = int(v[2])
	print(xor(a, b, n))


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])


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


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()


def calc():
	print()

def main():
	for _ in range(int(input())):
		arr: list = list(map(int, input().split()))
		temp: int = arr[-1] % 3
		if temp == 0:
			print(arr[0])
		elif temp == 1:
			print(arr[1])
		else:
			print(arr[0] ^ arr[1])
main()


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


import math

def decimal_to_binary_conversion(n):
	power = 0
	output_str = ''
	while 2 ** power <= n:
		power += 1
	for i in range(1, power + 1):
		index = power - i
		if n >= 2 ** index:
			output_str += '1'
			n -= 2 ** index
		else:
			output_str += '0'
	return output_str

def binary_to_decimal_conversion(s):
	output = 0
	for i in range(len(s)):
		j = len(s) - 1 - i
		output += 2 ** j * int(s[i])
	return output

def xor_operation(s1, s2):
	difference = max(len(s1), len(s2)) - min(len(s1), len(s2))
	if len(s1) > len(s2):
		s2 = '0' * difference + s2
	else:
		s1 = '0' * difference + s1
	output = ''
	for i in range(len(s1)):
		if s2[i] != s1[i]:
			output += '1'
		else:
			output += '0'
	return output

def main_function():
	output_list = []
	for i in range(int(input())):
		(a, b, n) = [int(i) for i in input().split(' ')]
		c = binary_to_decimal_conversion(xor_operation(decimal_to_binary_conversion(a), decimal_to_binary_conversion(b)))
		if not n % 3:
			output_list.append(str(a))
		elif n % 3 == 2:
			output_list.append(str(c))
		else:
			output_list.append(str(b))
	return '\n'.join(output_list)
print(main_function())


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


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)


from sys import stdin, stdout
for i in stdin:
	t = int(i)
	break

def xorinate(a, b):
	x = 0
	j = 0
	while a or b:
		if a % 2 != b % 2:
			x += 2 ** j
		a //= 2
		b //= 2
		j += 1
	return x
while t:
	for i in stdin:
		(a, b, n) = map(int, i.strip().split())
		break
	x = xorinate(a, b)
	stdout.write(str([a, b, x][n % 3]) + '\n')
	t -= 1


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])


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


for _ in ' ' * int(input()):
	(a, b, c) = map(int, input().split())
	d = 0
	print([a, b, a ^ b][c % 3])


res = {0: lambda x, y: x, 1: lambda x, y: y, 2: lambda x, y: x ^ y}
for _ in range(int(input())):
	(f1, f2, n) = map(int, input().split())
	val = res[n % 3](f1, f2)
	print(val)


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])


import sys
input = sys.stdin.readline
T = int(input())
for _ 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)


import io
import os
import sys
from atexit import register
import random
import math
import itertools
DEBUG = False
STRESSTEST = False
if not DEBUG:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda : os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0

def nextStr():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = input().split()
		tokens_next = 0
	tokens_next += 1
	if type(tokens[tokens_next - 1]) == str:
		return tokens[tokens_next - 1]
	return tokens[tokens_next - 1].decode()

def nextInt():
	return int(nextStr())

def nextIntArr(n):
	return [nextInt() for i in range(n)]

def print(*argv, end='\n'):
	for arg in argv:
		sys.stdout.write((str(arg) + ' ').encode())
	sys.stdout.write(end.encode())

def genTestCase():
	raise NotImplementedError

def bruteforce(a):
	raise NotImplementedError

def doStressTest():
	while True:
		curTest = genTestCase()
		mySoln = solve(curTest)
		bruteforceSoln = bruteforce(curTest)
		if mySoln != bruteforceSoln:
			print('### Found case ###')
			print(curTest)
			print(f'{mySoln} should have been: {bruteforceSoln}')
			return

def solve(a, b, n):
	return [a, b, a ^ b][n % 3]
if not DEBUG and STRESSTEST:
	raise Exception('Wrong flags!')
if STRESSTEST:
	doStressTest()
else:
	t = nextInt()
	for _ in range(t):
		a = nextInt()
		b = nextInt()
		n = nextInt()
		print(solve(a, b, n))
sys.stdout.flush()


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


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)


n = int(input())

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


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()


from __future__ import division, print_function
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
from fractions import Fraction

def ii():
	return int(input())

def si():
	return str(input())

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

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

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

def fsi():
	return str(stdin.readline())

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

def fli():
	return list(fmi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

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

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = {}
	for i in range(n):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)
t = ii()
for a0 in range(t):
	(a, b, n) = mi()
	if n % 3 == 0:
		print(a)
	elif n % 3 == 1:
		print(b)
	else:
		print(a ^ b)


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 _10to2(n):
	a = []
	while n > 0:
		a.append(n % 2)
		n = n // 2
	a.reverse()
	return a

def _2to10(a):
	n = 0
	a.reverse()
	for i in range(len(a)):
		n += 2 ** i * a[i]
	return n
for i in range(int(input())):
	(a, b, n) = (int(x) for x in input().split())
	if n == 0:
		print(a)
		continue
	if n == 1:
		print(b)
		continue
	bin_a = _10to2(a)
	bin_b = _10to2(b)
	while len(bin_a) < len(bin_b):
		bin_a.insert(0, 0)
	while len(bin_b) < len(bin_a):
		bin_b.insert(0, 0)
	c = []
	for i in range(len(bin_a)):
		if bin_a[i] == bin_b[i] == 0:
			c.append(0)
		elif bin_a[i] == 0 and bin_b[i] == 1:
			if n % 3 == 0:
				c.append(0)
			else:
				c.append(1)
		elif bin_a[i] == 1 and bin_b[i] == 0:
			if n % 3 == 1:
				c.append(0)
			else:
				c.append(1)
		elif bin_a[i] == 1 and bin_b[i] == 1:
			if n % 3 == 2:
				c.append(0)
			else:
				c.append(1)
	print(_2to10(c))


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)


n = int(input())

def oo(x):
	return 0

def ob(x):
	if x % 3 == 2:
		return 0
	else:
		return 1

def bo(x):
	if x % 3 == 0:
		return 0
	else:
		return 1

def bb(x):
	if x % 3 == 1:
		return 0
	else:
		return 1
for i in range(n):
	q = list(map(int, input().split()))
	a = bin(q[0])[2:]
	b = bin(q[1])[2:]
	x = q[2] - 1
	l = []
	if len(a) > len(b):
		b = (len(a) - len(b)) * '0' + b
	else:
		a = (len(b) - len(a)) * '0' + a
	for i in range(len(a)):
		if a[i] == '1' and b[i] == '0':
			l.append(bo(x))
		elif a[i] == '0' and b[i] == '0':
			l.append(oo(x))
		elif a[i] == '0' and b[i] == '1':
			l.append(ob(x))
		else:
			l.append(bb(x))
	res = ''.join(map(str, l))
	print(int(res, 2))


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))


def mp():
	return map(int, input().split())
q = int(input())
for qq in range(q):
	(a, b, n) = mp()
	s = [a]
	for i in range(n % 3):
		(a, b) = (b, a ^ b)
		s.append(a)
	print(a)


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)


import os
import sys
from io import BytesIO, IOBase

def solution(a, b, n):
	fib = [a, b]
	while a ^ b not in fib:
		fib.append(a ^ b)
		(a, b) = (fib[-2], fib[-1])
	write(fib[n % 3])

def main():
	for _ in range(r_int()):
		(a, b, n) = r_array()
		solution(a, b, n)
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')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def w_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


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))


n = int(input())
for i in range(n):
	aa = []
	(a, b, c) = map(int, input().split())
	if c <= 1:
		if c == 1:
			print(b)
		else:
			print(a)
	else:
		aa.append(a ^ b)
		d = a ^ b
		a = b
		b = d
		for i in range(2):
			d = a ^ b
			a = b
			b = d
			if d == aa[0]:
				break
			else:
				aa.append(d)
		print(aa[(c - 1) % len(aa) - 1])


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 [0] * int(input()):
	(a, b, n) = map(int, input().split())
	(r, m) = (0, 1)
	while a or b:
		r |= m * (a, b, a ^ b)[n % 3]
		a >>= 1
		b >>= 1
		m <<= 1
	print(r)


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)


from sys import setcheckinterval, stdin
setcheckinterval(1000)

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

def lin():
	return list(map(int, stdin.readline().split()))
for _ in range(iin()):
	(a, b, n) = lin()
	sol = [a, b, a ^ b]
	print(sol[n % 3])


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)


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
INF = 1 << 60
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:
		print(a ^ b)


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)


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

def main():
	Tests = int(input())
	if 1 <= Tests <= pow(10, 3):
		Results = []
		for i in range(Tests):
			(a, b, n) = map(int, input().split())
			if 0 <= a <= pow(10, 9) and 0 <= b <= pow(10, 9) and (0 <= n <= pow(10, 9)):
				Results.append(Xorinacci(n, a, b))
	for i in range(len(Results)):
		print(Results[i])
main()


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))


no_of_testcases = int(input())

def convert_to_binary(binary_list):
	length_of_final_list = len(binary_list)
	counter = length_of_final_list - 1
	decimal_no = 0
	while counter >= 0:
		decimal_no = decimal_no + int(binary_list[counter]) * pow(2, length_of_final_list - 1 - counter)
		counter = counter - 1
	return decimal_no

def make_same_length(number1, number2):
	len1 = len(number1)
	len2 = len(number2)
	difference = len1 - len2
	if difference == 0:
		return (number1, number2)
	if difference > 0:
		addition = '0' * difference
		return (number1, addition + number2)
	if difference < 0:
		addition = '0' * -difference
		return (addition + number1, number2)
for i in range(no_of_testcases):
	offset = {}
	offset['01'] = 0
	offset['11'] = 1
	offset['10'] = 2
	binary_value_list = ['1', '0', '1']
	(number1, number2, number_of_additions) = list(map(int, input().split(' ')))
	number1 = bin(number1).replace('0b', '')
	number2 = bin(number2).replace('0b', '')
	(number1, number2) = make_same_length(number1, number2)
	string_list = []
	for i in range(len(number1)):
		string_list.append(number1[i] + number2[i])
	final_list = []
	for i in string_list:
		if i == '00':
			final_list.append('0')
		else:
			final_list.append(binary_value_list[(offset[i] + number_of_additions + 1) % 3])
	decimal_no = convert_to_binary(final_list)
	print(decimal_no)


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)


t = int(input())
for each in range(t):
	nlist = input().split(' ')
	if int(nlist[2]) % 3 == 2:
		print(int(nlist[0]) ^ int(nlist[1]))
	else:
		print(nlist[int(nlist[2]) % 3])


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()


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


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)


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


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)