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:
#__author__ = 'guluuu3'
from math import sqrt
def factors(n):
    return [(i,n/i) for i in range(1,int(sqrt(n))+1) if not n%i]
t=input()
while(t):
    d,p=map(int,raw_input().split())
    flag=False
    for i,j in factors(p):
        if j-i==d:
            flag=True
            break
    if (flag==True):
        print 4 if j!=i else 2
    else:
        print 4 if p==0 else 0
    t=t-1