The Fibonacci sequence is defined as F(n) = F(n-1) + F(n-2). You have developed two sequences of numbers. The first sequence that uses the bitwise XOR operation instead of the addition method is called the Xoronacci number. It is described as follows:
X(n) = X(n-1) XOR X(n-2)
The second sequence that uses the bitwise XNOR operation instead of the addition method is called the XNoronacci number. It is described as follows:
E(n) = E(n-1) XNOR E(n-2)
The first and second numbers of the sequence are as follows:
X(1) = E(1) = a
X(2) = E(2) = b
Your task is to determine the value of max(X(n),E(n)), where n is the n th term of the Xoronacci and XNoronacci sequence.

-----Input:-----
The first line consists of a single integer T denoting the number of test cases.
The first and the only line of each test case consists of three space separated integers a, b and n.

-----Output:-----
For each test case print a single integer max(X(n),E(n)).

-----Constraints-----
- $1 \leq T \leq 1000$
- $2 \leq a,b,n \leq 1000000000000$

-----Sample Input:-----
1
3 4 2 

-----Sample Output:-----
4

-----EXPLANATION:-----
Xoronacci Sequence : 3 4 7 …….
XNoronacci Sequence : 3 4 0 …….
Here n = 2. Hence max(X(2),E(2)) = 4

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
import math

def swap(a, b):
	temp = a
	a = b
	b = temp

def xnor(a, b):
	if a < b:
		swap(a, b)
	if a == 0 and b == 0:
		return 1
	a_rem = 0
	b_rem = 0
	count = 0
	xnornum = 0
	while a != 0:
		a_rem = a & 1
		b_rem = b & 1
		if a_rem == b_rem:
			xnornum |= 1 << count
		count = count + 1
		a = a >> 1
		b = b >> 1
	return xnornum
t = int(input())
for o in range(t):
	(a, b, n) = map(int, input().split())
	c = a ^ b
	x = bin(c)
	x = x.split('b')
	x = x[1]
	x = len(x)
	d = xnor(a, b)
	p = [a, b, c]
	r = [a, b, d]
	k = n % 3 - 1
	if p[k] > r[k]:
		print(p[k])
	else:
		print(r[k])


import math

def xnor(num1, num2):
	if num1 < num2:
		temp = num1
		num1 = num2
		num2 = temp
	num1 = togglebit(num1)
	return num1 ^ num2

def togglebit(n):
	if n == 0:
		return 1
	i = n
	n = n | n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	return i ^ n
for _ in range(int(input())):
	(a, b, n) = [int(i) for i in input().split()]
	xoro = [a, b, a ^ b]
	xnoro = [a, b]
	index = 2
	while index != 8:
		xnoro.append(xnor(xnoro[index - 1], xnoro[index - 2]))
		index += 1
	if n > 8:
		print(max(xoro[n % 3 - 1], xnoro[n % 3 + 5]))
	else:
		print(max(xoro[n % 3 - 1], xnoro[n - 1]))


def xnor(a, b):
	if a == 0:
		return 1 ^ b
	p = a
	a = a | a >> 1
	a = a | a >> 2
	a = a | a >> 4
	a = a | a >> 8
	a = a | a >> 16
	a = a | a >> 32
	a = a | a >> 64
	return a ^ p ^ b

def solve():
	(a, b, n) = list(map(int, input().split()))
	n -= 1
	index = n % 3
	if index == 0:
		print(a)
	elif index == 1:
		print(b)
	else:
		x = a ^ b
		e = xnor(max(a, b), min(a, b))
		print(max(x, e))
for _ in range(int(input())):
	solve()


def xnor(a, b):
	if a == 0:
		return 1 ^ b
	p = a
	a = a | a >> 1
	a = a | a >> 2
	a = a | a >> 4
	a = a | a >> 8
	a = a | a >> 16
	a = a | a >> 32
	a = a | a >> 64
	return a ^ p ^ b

def solve():
	(a, b, n) = list(map(int, input().split()))
	n -= 1
	index = n % 3
	if index == 0:
		print(a)
	elif index == 1:
		print(b)
	else:
		x = a ^ b
		e = xnor(max(a, b), min(a, b))
		print(max(x, e))
t = int(input())
while t > 0:
	solve()
	t = t - 1


import math

def togglebit(n):
	if n == 0:
		return 1
	i = n
	n = n | n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	return i ^ n

def xnor(num1, num2):
	if num1 < num2:
		temp = num1
		num1 = num2
		num2 = temp
	num1 = togglebit(num1)
	return num1 ^ num2

def x(A, B, N):
	if N == 1:
		return A
	elif N == 2:
		return B
	else:
		t0 = A ^ B
		t1 = B ^ t0
		t2 = t0 ^ t1
		if N % 3 == 0:
			return t0
		elif N % 3 == 1:
			return t1
		else:
			return t2

def xn(A, B, N):
	if N == 1:
		return A
	elif N == 2:
		return B
	else:
		cache = [xnor(A, B)]
		cache.append(xnor(cache[0], B))
		for i in range(2, 7):
			cache.append(xnor(cache[i - 1], cache[i - 2]))
		t1 = xnor(cache[6], cache[5])
		t2 = xnor(cache[6], t1)
		t0 = xnor(t2, t1)
		if N <= 9:
			return cache[N - 3]
		elif N % 3 == 0:
			return t0
		elif N % 3 == 1:
			return t1
		else:
			return t2
t = int(input())
for _ in range(t):
	(p, q, n) = map(int, input().split())
	print(max(x(p, q, n), xn(p, q, n)))


def togglebit(n):
	if n == 0:
		return 1
	i = n
	n = n | n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	return i ^ n

def xnor(num1, num2):
	if num1 < num2:
		temp = num1
		num1 = num2
		num2 = temp
	num1 = togglebit(num1)
	return num1 ^ num2

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

def nthXnorFib(n, a, b):
	if n == 0:
		return a
	if n == 1:
		return b
	if n == 2:
		return xnor(a, b)
	return nthXnorFib(n % 3, a, b)
t = int(input())
while t:
	(a, b, n) = map(int, input().split())
	print(max(nthXnorFib(n - 1, a, b), nthXorFib(n - 1, a, b)))
	t -= 1


def togglebit(n):
	if n == 0:
		return 1
	i = n
	n |= n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	return i ^ n

def xnor(num1, num2):
	if num1 < num2:
		temp = num1
		num1 = num2
		num2 = temp
	num1 = togglebit(num1)
	return num1 ^ num2

def xn(a, b, n):
	f = [0] * 3
	f[0] = a
	f[1] = b
	f[2] = xnor(a, b)
	if n % 3 == 0:
		return f[2]
	else:
		return f[n % 3 - 1]

def fib(a, b, n):
	f = [0] * 3
	f[0] = a
	f[1] = b
	f[2] = a ^ b
	if n % 3 == 0:
		return f[2]
	else:
		return f[n % 3 - 1]

def __starting_point():
	for _ in range(int(input())):
		(a, b, n) = list(map(int, input().split()))
		print(max(fib(a, b, n), xn(a, b, n)))
__starting_point()


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	(a, b, n) = map(int, input().split())
	c = a ^ b
	c1 = bin(c).lstrip('0b')
	c1 = list(c1.rjust(max(len(bin(a)), len(bin(b))) - 2, '0'))
	for j in range(len(c1)):
		if c1[j] == '0':
			c1[j] = '1'
		else:
			c1[j] = '0'
	c1 = int(''.join(c1), 2)
	l = [a, b, max(c, c1)]
	ans = l[(n - 1) % 3]
	print(ans)


from sys import stdin
import math

def togglebit(n):
	if n == 0:
		return 1
	i = n
	n = n | n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	return i ^ n

def xnor(num1, num2):
	if num1 < num2:
		temp = num1
		num1 = num2
		num2 = temp
	num1 = togglebit(num1)
	return num1 ^ num2
for _ in range(int(stdin.readline())):
	(a, b, n) = list(map(int, stdin.readline().split()))
	X = [a, b, a ^ b]
	E = [a, b]
	for i in range(2, n):
		E.append(xnor(E[-1], E[-2]))
		if E[-3:] == E[-6:-3]:
			break
	x = (n - 1) % 3
	e = (n - len(E)) % 3
	if e == 0:
		e = -1
	elif e == 1:
		e = -3
	else:
		e = -2
	print(max(X[x], E[e]))


import math

def xnor(a, b):
	if a < b:
		(a, b) = (b, a)
	if a == 0 and b == 0:
		return 1
	a_rem = 0
	b_rem = 0
	count = 0
	xnornum = 0
	while a != 0:
		a_rem = a & 1
		b_rem = b & 1
		if a_rem == b_rem:
			xnornum |= 1 << count
		count = count + 1
		a = a >> 1
		b = b >> 1
	return xnornum
for _ in range(int(input())):
	(a, b, n) = map(int, input().split())
	X = [a, b, a ^ b]
	E = [a, b, xnor(a, b)]
	i = (n - 1) % 3
	print(max(X[i], E[i]))


def xnor(a, b):
	if a < b:
		(a, b) = (b, a)
	if a == 0 and b == 0:
		return 1
	a_rem = 0
	b_rem = 0
	count = 0
	xnornum = 0
	while a:
		a_rem = a & 1
		b_rem = b & 1
		if a_rem == b_rem:
			xnornum |= 1 << count
		count += 1
		a = a >> 1
		b = b >> 1
	return xnornum

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

def check(a, b, n):
	if n == 1:
		return a
	elif n == 2:
		return b
	if n <= 6:
		ans = xnor(a, b)
		for i in range(3, n):
			(ans, b) = (xnor(ans, b), ans)
		return ans
	elif (n - 4) % 3 == 0:
		return a
	elif (n - 5) % 3 == 0:
		return b
	elif (n - 6) % 3 == 0:
		return xnor(a, b)
for z in range(int(input())):
	(a, b, n) = map(int, input().split())
	print(max(xor(a, b, n), check(a, b, n)))


import math

def swap(a, b):
	temp = a
	a = b
	b = temp

def xnor(a, b):
	if a < b:
		swap(a, b)
	if a == 0 and b == 0:
		return 1
	a_rem = 0
	b_rem = 0
	count = 0
	xnornum = 0
	while a != 0:
		a_rem = a & 1
		b_rem = b & 1
		if a_rem == b_rem:
			xnornum |= 1 << count
		count = count + 1
		a = a >> 1
		b = b >> 1
	return xnornum

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

def nthXNorFib(n, a, b):
	if n == 0:
		return a
	if n == 1:
		return b
	if n == 2:
		return xnor(a, b)
	return nthXNorFib(n % 3, a, b)
for test in range(int(input())):
	(a, b, n) = map(int, input().split())
	print(max(nthXNorFib(n - 1, a, b), nthXorFib(n - 1, a, b)))


t = int(input())
for x in range(t):
	(a, b, n) = list(map(int, input().split()))
	import math

	def togglebit(n):
		if n == 0:
			return 1
		i = n
		n = n | n >> 1
		n |= n >> 2
		n |= n >> 4
		n |= n >> 8
		n |= n >> 16
		return i ^ n

	def xnor(num1, num2):
		if num1 < num2:
			temp = num1
			num1 = num2
			num2 = temp
		num1 = togglebit(num1)
		return num1 ^ num2

	def xor(x, y, p):
		if p % 3 == 1:
			return x
		elif p % 3 == 2:
			return y
		elif p % 3 == 0:
			return x ^ y

	def xnnor(x, y, p):
		if p % 3 == 1:
			return x
		elif p % 3 == 2:
			return y
		elif p % 3 == 0:
			return xnor(x, y)
	print(max(xor(a, b, n), xnnor(a, b, n)))


def binary(x):
	result = []
	while x != 0:
		temp = x % 2
		x = x // 2
		result.append(temp)
	return result

def binCount(x):
	count = 0
	while x != 0:
		x = x // 2
		count += 1
	return count

def xnor(a, b):
	final = []
	count = max(binCount(a), binCount(b))
	abin = binary(a)
	bbin = binary(b)
	if count != len(abin):
		while len(abin) != count:
			abin.append(0)
	if count != len(bbin):
		while len(bbin) != count:
			bbin.append(0)
	i = 0
	while i < count:
		if bbin[i] == 0 and abin[i] == 0 or (bbin[i] == 1 and abin[i] == 1):
			final.append(1)
		else:
			final.append(0)
		i += 1
	ans = 0
	i = 0
	for dig in final:
		ans += dig * 2 ** i
		i += 1
	return ans
tulu = int(input())
for _ in range(tulu):
	(a, b, n) = [int(x) for x in input().split()]
	x = a ^ b
	y = xnor(a, b)
	value1 = x
	value2 = y
	if n % 3 == 1:
		value1 = a
		value2 = a
	if n % 3 == 2:
		value2 = b
		value1 = b
	print(max(value1, value2))


t = int(input())

def xnor(a, b):
	if a < b:
		(a, b) = (b, a)
	if a == 0 and b == 0:
		return 1
	a_rem = 0
	b_rem = 0
	count = 0
	xnornum = 0
	while a != 0:
		a_rem = a & 1
		b_rem = b & 1
		if a_rem == b_rem:
			xnornum |= 1 << count
		count = count + 1
		a = a >> 1
		b = b >> 1
	return xnornum
while t:
	t -= 1
	(a, b, n) = input().split()
	(a, b, n) = (int(a), int(b), int(n))
	if n % 3 == 1:
		print(a)
		continue
	if n % 3 == 2:
		print(b)
		continue
	xor_ = a ^ b
	xnor_ = xnor(a, b)
	print(max(xor_, xnor_))