CodeforcesAug 01, 2025

XORinacci

Hazrat Ali

Codeforces

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:

You are given three integers ab, 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 (1T103), the number of test cases.

Each of the T following lines contains three space-separated integers ab, and n (0a,b,n109) 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

Solution

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    long long a, b, n;
    cin >> a >> b >> n;
    if (n % 3 == 0) {
      cout << a << endl;
    } else if (n % 3 == 1) {
      cout << b << endl;
    } else {
      cout << (a xor b) << endl;
    }
  }
  return 0;
}





Comments