Problem A: XOR Fibonacci

Problem A: XOR Fibonacci

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 790  Solved: 272
[Submit][Status][Web Board]

Description

Pisces now defines a sequence as follows:

$$ f(n)=\left\{
\begin{aligned}
&a, & n = 0 \\
&b, & n = 1 \\
&f(n-2)⊕ f(n-1), & n > 1
\end{aligned}
\right.
$$

where ⊕ denotes the bitwise XOR operation. Now you are given three integers \(a, b\) and \(n\), calculate \(f(n)\).

You have to answer \(T\) independent test cases.

Input

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

Each of the following \(T\) lines contains three integers \(a, b\) and \(n(0\leq a, b, n\leq 10^9)\).

Output

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

Sample Input

3
3 4 2
4 5 0
325 265 1231232

Sample Output

7
4
76

HINT

[Submit][Status]