import sys input = sys.stdin.buffer.readline 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 (x, y) in memo: print(memo[x, y]) continue if diff == 0: cnt += x - 1 # b * (a + 1) = x divisors = make_divisors(x) cnt += (len(divisors) - 1) memo[(x, y)] = cnt print(cnt) continue divisors = make_divisors(diff) for div in divisors: a = div + 1 # b + c = sum_ // (a + 1) # b - c = diff // (a - 1) if sum_ % (a + 1) != 0: continue t1 = sum_ // (a + 1) t2 = 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 memo[(x, y)] = cnt print(cnt)