CF1208A.XORinacci

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

XORinacci

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)=af(0) = a;
  • f(1)=bf(1) = b;
  • f(n)=f(n1)f(n2)f(n) = f(n-1) \oplus f(n-2) when n>1n \gt 1, where \oplus denotes the bitwise XOR operation.

You are given three integers aa, bb, and nn, calculate f(n)f(n).

You have to answer for TT independent test cases.

Input

The input contains one or more independent test cases.

The first line of input contains a single integer TT (1T1031 \le T \le 10^3), the number of test cases.

Each of the TT following lines contains three space-separated integers aa, bb, and nn (0a,b,n1090 \le a, b, n \le 10^9) respectively.

Output

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

Note

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

Samples

3
3 4 2
4 5 0
325 265 1231232
7
4
76

在线编程 IDE

建议全屏模式获得最佳体验