def divisors(M):#Mの約数列 O(n^(0.5+e)) d=[] i=1 while M>=i**2: if M%i==0: d.append(i) if i**2!=M: d.append(M//i) i=i+1 return d import sys input= sys.stdin.readline for _ in range(int(input())): x,y = map(int,input().split()) div = divisors(x+y) count = 0 for d in div: count+=1 print(count)