import sys input = sys.stdin.buffer.readline def make_divisors(n): for i in range(1, int(n ** 0.5) + 1): if n % i == 0: yield i if i != n // i: yield n // i def solve(X, Y): res = 0 if X == Y: res += X + 1 for div in make_divisors(abs(X - Y)): if (X + Y) % (div + 2): continue BpC = (X + Y) // (div + 2) BmC = abs(X - Y) // div if BpC >= BmC and not (BpC & 1) ^ (BmC & 1): res += 1 return res S = int(input()) for _ in range(S): print(solve(*map(int, input().split())))