#P5491. 【模板】二次剩余

【模板】二次剩余

Description

Given N,pN, p, solve the equation

x2N(modp)x^2 \equiv N \pmod{p}

There are multiple test cases, and it is guaranteed that pp is an odd prime.

Input Format

Line 11 contains an integer TT, which indicates the number of test cases.

Lines 22 to T+1T + 1 each contain two integers NN and pp. Their meanings are described in the statement.

Output Format

Output a total of TT lines.

For each line of output, if there is a solution, output all solutions modulo pp in increasing order after taking mod p\bmod~ p. If the two solutions are the same, output only one of them. If there is no solution, output Hola!.

3
5 1000000009
4 1000000009
0 19260817
383008016 616991993
2 1000000007
0

Hint

For 100%100\% of the testdata, 1T1041 \le T \le 10^4, 0N,p109+90 \le N, p \le 10^9 + 9.

Translated by ChatGPT 5