Trinomial

No attempts yetTime limit3sMemory limit128 MB

Problem

Consider the trinomial (x2+x+1)n(x^2 + x + 1)^n. We study the coefficients cic_i that appear when this expression is expanded:

c0+c1x+c2x2++c2nx2nc_0 + c_1 x + c_2 x^2 + \dots + c_{2n} x^{2n}

For example, (x2+x+1)3=1+3x+6x2+7x3+6x4+3x5+x6(x^2 + x + 1)^3 = 1 + 3x + 6x^2 + 7x^3 + 6x^4 + 3x^5 + x^6.

Write a program that:

  • reads several data sets, each consisting of two numbers nn and ii,
  • for each data set computes cimod3c_i \bmod 3, where cic_i is the coefficient of xix^i in the expansion of (x2+x+1)n(x^2 + x + 1)^n,
  • writes each computed value to the standard output.

Input

The first line contains one integer kk, the number of data sets, where 1k100001 \le k \le 10000.

It is followed by kk data sets, one per line. Each set consists of two non-negative integers nn and ii separated by a single space, where 0n10150 \le n \le 10^{15} and 0i2n0 \le i \le 2n.

Output

Output kk lines. The jj-th line must contain a single non-negative integer equal to cimod3c_i \bmod 3 for the jj-th data set.