import functools import sys input = sys.stdin.buffer.readline @functools.lru_cache(maxsize=10**5) def make_divisors(n: int) -> list: """自然数nの約数を列挙したリストを出力する 計算量: O(sqrt(N)) 入出力例: 12 -> [1, 2, 3, 4, 6, 12] """ divisors = [] for k in range(1, int(n ** 0.5) + 1): if n % k == 0: divisors.append(k) if k != n // k: divisors.append(n // k) return divisors s = int(input()) memo = {} for _ in range(s): x, y = map(int, input().split()) if x < y: x, y = y, x sum_ = x + y diff = x - y cnt = 0 if diff == 0: cnt += x - 1 # b * (a + 1) = x cnt += (len(make_divisors(x)) - 1) print(cnt) continue for div in make_divisors(diff): a = div + 1 # b + c = sum_ // (a + 1) # b - c = diff // (a - 1) if sum_ % (a + 1) != 0: continue t1, t2 = sum_ // (a + 1), diff // (a - 1) if (t1 + t2) % 2 == 1: continue b, c = (t1 + t2) // 2, (t1 - t2) // 2 if b > 0 and c > 0: cnt += 1 print(cnt)