QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#12983. Trinomial

统计

Consider a trinomial $(x^2+x+1)^n$. We are interested in the coefficients $c_i$ of the expansion of this trinomial:

$$c_0 + c_1x + c_2x^2 + \cdots + c_{2n}x^{2n}$$

For example, $(x^2+x+1)^3=1+3x+6x^2+7x^3+6x^4+3x^5+x^6$.

Task

Write a program which:

  • reads from the standard input sets of data that comprise numbers $n$ and $i$,
  • for each set of data computes $c_i$ modulo $3$, where $c_i$ is the coefficient of $x_i$ in the expansion of the trinomial $(x^2+x+1)^n$,
  • for each set of data writes the computed number to the standard output.

Input

In the first line of the standard input there is one integer $k$ denoting the number of the data sets, $1 \le k \le 10\,000$. It is followed by $k$ sets of data, one per line. Each set consists of two non-negative integers $n$ and $i$ separated by a single space, $0 \le n \le 1\,000\,000\,000\,000\,000$, $0 \le i \le 2n$.

Output

One should write $k$ lines to the standard output. The $j$-th line ought to contain one non-negative integer being $c_i$ modulo $3$ for the numbers from the $j$-th set.

Example

Input

5
2 0
7 4
4 5
5 3
8 15

Output

1
2
1
0
2
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.