TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

In every city of Triangle Country, all the enclosed blocks of streets are equilateral triangles with same area. In one of the city X, there is a main street across the city. Everyday Shik takes a walk starting from his home (located somewhere on the main street), and walking through n segment of streets. As usual, Shik feels somewhat puzzled and gets lost again. Therefore, he wishes back to the main street after he walks through n segment of streets. Please help Shik to calculate how many available routes that he can choose.

Input Format

First line contains an integer T(1<=T<=100) indicating the number of test cases.


For each test case, there are an integer n (1<=n<=106) indicating the number of segments Shik will walk through and a prime number m (2<=m<=2*109).

Output Format

For each test case, please output the number of available routes modulo m.

Sample Input 1

3
1 11
2 2
3 3

Sample Output 1

2
0
2

Hints

Problem Source

Migrated from old NTUJ.

Shik and Tmt

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 5000 65536 200