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

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.