import sys import math def get_divisors(n): divisors = set() for i in range(1, int(math.isqrt(abs(n))) + 1): if n % i == 0: divisors.add(i) divisors.add(-i) divisors.add(n // i) divisors.add(-n // i) return divisors def count_solutions(X, Y): D = Y - X solutions = 0 if D == 0: total = 2 * Y for A in range(2, int(math.isqrt(total)) + 2): if (A + 1) != 0 and total % (A + 1) == 0: C = (Y * A - X) // (A * A - 1) if C <= 0: continue if (X - C) % A != 0: continue B = (X - C) // A if B <= 0: continue solutions += 1 else: divisors = get_divisors(D) for d in divisors: if d <= 0: continue A = d + 1 total = X + Y if (A + 1) == 0: continue if total % (A + 1) != 0: continue numerator = Y * A - X denominator = A * A - 1 if denominator == 0: continue if numerator % denominator != 0: continue C = numerator // denominator if C <= 0: continue if (X - C) % A != 0: continue B = (X - C) // A if B <= 0: continue solutions += 1 return solutions def main(): input = sys.stdin.read().split() S = int(input[0]) idx = 1 for _ in range(S): X = int(input[idx]) Y = int(input[idx + 1]) idx += 2 print(count_solutions(X, Y)) if __name__ == '__main__': main()