#P5947. [POI 2003] Trinomial

[POI 2003] Trinomial

Problem Description

Find the coefficient of the ii-th term of (x2+x+1)n(x^2 + x + 1)^n.

Input Format

The first line contains an integer kk, the number of test cases.

The next kk lines each contain two integers n,in, i.

Output Format

For each test case, output the result of ximod3x_i \bmod 3.

5
2 0
7 4
4 5
5 3
8 15
1
2
1
0
2

Hint

Constraints: for 100%100\% of the testdata, 1k100001 \le k \le 10000, 0n10150 \le n \le 10^{15}, and 0i2×n0 \le i \le 2 \times n.

Translated by ChatGPT 5