Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
A
XORinacci
Codeforces
900
原题
←B →
翻译中…

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 \gt 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)$.

翻译中…

Note

翻译中…

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

翻译中…

样例

Input #1
3
3 4 2
4 5 0
325 265 1231232
Output #1
7
4
76
InputCopy OutputCopy
题目信息
题号
1208A
时间限制
1 s
内存限制
256 MB
标签
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。