def divisors(M):#Mの約数列 O(n^(0.5+e)) import math d=[] i=1 while math.sqrt(M)>=i: if M%i==0: d.append(i) if i**2!=M: d.append(M//i) i=i+1 d.sort() return d import sys for _ in range(int(input())): x,y = map(int,input().split()) div = divisors(x+y) count = 0 for d in div: if x!=y: if d==1 or d==2: continue if (x+y)%d!=0 or (x-y)%(d-2)!=0: continue s = (x + y) // d t = (x - y) // (d-2) if (s + t) % 2 !=0: continue b = (s + t) // 2 c = (s - t) // 2 if b>0 and c>0: count += 1 else: if d==1: continue if d==2: s = (x + y) // d count += s - 1 else: if ((x+y) // d) %2 ==0: count += 1 print(count)