#ARC158D. [ARC158D] Equation

[ARC158D] Equation

Score : 800800 points

Problem Statement

You are given a positive integer nn, and a prime number pp at least 55.

Find a triple of integers (x,y,z)(x,y,z) that satisfies all of the following conditions.

  • 1x<y<zp11\leq x < y < z \leq p - 1.
  • $(x+y+z)(x^n+y^n+z^n)(x^{2n}+y^{2n}+z^{2n}) \equiv x^{3n}+y^{3n}+z^{3n}\pmod{p}$.

It can be proved that such a triple (x,y,z)(x,y,z) always exists.

You have TT test cases to solve.

Constraints

  • 1T1051\leq T\leq 10^5
  • 1n1091\leq n\leq 10^9
  • pp is a prime number satisfying 5p1095\leq p\leq 10^9.

Input

The input is given from Standard Input in the following format:

TT

case1\text{case}_1

\vdots

caseT\text{case}_T

Each case is in the following format:

nn pp

Output

Print TT lines. The ii-th line should contain x,y,zx,y,z with spaces in between where (x,y,z)(x,y,z) is a solution for the ii-th test case.

If multiple solutions exist, you may print any of them.

3
1 7
2 7
10 998244353
1 4 6
1 2 5
20380119 21549656 279594297

For the first test case:

  • $(x+y+z)(x^n+y^n+z^n)(x^{2n}+y^{2n}+z^{2n}) = (1+4+6)(1+4+6)(1+16+36) = 6413$, and
  • x3n+y3n+z3n=1+64+216=281x^{3n}+y^{3n}+z^{3n} = 1 + 64 + 216 = 281.

We have 6413281(mod7)6413\equiv 281\pmod{7}, so the conditions are satisfied.