Michael is teaching his recitation and he's trying to come up with two numbers and
to use in a demonstration for his students. For the demonstration to work he know that
and
must be integers within the bounds
and
for given integers
and
. However Michael also knows that his students have very specific tastes: they will only pay attention to his demonstration if the sum
is a square number (i.e. there exists a non-negative integer
such that
).
Before Michael makes his choices for and
he wants to know how many valid choices he has. As such, compute the number of valid pairs
with a square sum. As the answer may be large, compute this value modulo
.
Michael will also be planning ahead for the next recitations and will have one question for each recitation.
Constraints
Subtask 1 [20%]
Subtask 2 [20%]
Subtask 3 [40%]
Subtask 4 [20%]
No additional constraints.
Input Specification
The first line contains the integer .
The following lines each contain two integers:
and
for each test case.
Output Specification
Output lines.
On the th line output a single integer - the number of valid pairs with square sum for testcase
, reduced modulo
.
Sample Input
3
3 5
9982 44353
123456789 123456789
Sample Output
7
1551747
923038039
Note
The true answer for the third case of the sample is 757592257613
prior to the modulo operation.
Comments