1208_A. XORinacci_619
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) ⊕ f(n-2) when n > 1, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). 



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 ≤ T ≤ 10^3), the number of test cases.

Each of the T following lines contains three space-separated integers a, b, and n (0 ≤ a, b, n ≤ 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) ⊕ f(1) = 3 ⊕ 4 = 7.
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
 
#sys.setrecursionlimit(10**6)
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)		

	

Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.

### Description:
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) ⊕ f(n-2) when n > 1, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). 



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 ≤ T ≤ 10^3), the number of test cases.

Each of the T following lines contains three space-separated integers a, b, and n (0 ≤ a, b, n ≤ 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) ⊕ f(1) = 3 ⊕ 4 = 7.

### Input:
3
3 4 2
4 5 0
325 265 1231232

### Output:
7
4
76


### Input:
10
669924290 408119795 804030560
663737793 250734602 29671646
431160679 146708815 289491233
189259304 606497663 379372476
707829111 49504411 81710658
54555019 65618101 626948607
578351356 288589794 974275296
400531973 205638174 323247740
219131617 178762989 799964854
825160173 502080627 608216046

### Output:
1069371953
696139211
286024744
189259304
707829111
54555019
578351356
463366171
178762989
825160173


### Code:
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
 
#sys.setrecursionlimit(10**6)
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)		

	
