Problem: Tim likes Math. He likes it so much that he always brings his tablets with him and reads math e-books everywhere, even during parties.

Tim found an interesting exercise in one of the e-books he is reading. But you want him to join the party, so you decide to answer the question for him.

The problem is: Given D and P, how many ordered pairs of integers are there whose absolute difference is D and whose product is P? In other words, how many pairs of integers (A,B) are there such that:

|A−B|=D
A×B=P

SAMPLE INPUT
3
1 2
0 4
-1 1

SAMPLE OUTPUT
4
2
0

Solution (in PYTHON):

Solution:
from math import sqrt

def is_perfect_square(y):
    if y < 0:
        return False
    x = int(sqrt(y))
    while x * x < y: x += 1
    while x * x > y: x -= 1
    return x * x == y

def f(d,p):
    y = d*d + 4*p
    if d < 0 or not is_perfect_square(y):
        return 0
    return 1 << (d>0) + (y>0)

for cas in xrange(input()):
    d, p = map(int, raw_input().strip().split())
    print f(d,p)