def subsolve(x): ans = 0 for i in range(1, x): if i * i > x: break if x % i: continue if x // i - 1 > 0: ans += 1 if x != i * i and x // (x // i) - 1 > 0: ans += 1 ans += x print(ans) def solve(): x, y = map(int, input().split()) if x == y: subsolve(x) return if x < y: x, y = y, x ans = 0 su, sv, tu, tv = [], [], [], [] for a in range(1, x + y): if a * a > x + y: break if (x + y) % a: continue su.append(a - 1) if (x + y) // a != a: sv.append((x + y) // a - 1) for a in range(1, x - y): if a * a > x - y: break if (x - y) % a: continue tu.append(a + 1) if (x - y) // a != a: tv.append((x - y) // a + 1) sv.reverse() s = su s.extend(sv) tv.reverse() t = tu t.extend(tv) i, j = 0, 0 ans = 0 while i < len(s) and j < len(t): if s[i] != t[j]: if s[i] < t[j]: i += 1 else: j += 1 else: a = s[i] if a - 1 > 0: bpc = (x + y) // (a + 1) bmc = (x - y) // (a - 1) b = (bpc + bmc) // 2 c = x - a * b if b > 0 and c > 0 and a * c + b == y: ans += 1 i += 1 j += 1 print(ans) t = int(input()) for _ in range(t): solve()