for _ in range(int(input())): x, y = map(int, input().split()) if x < y: x, y = y, x p = x + y q = x - y d = 1 ans = 0 while d * d <= q: if q % d == 0: d2 = q // d for s, t in ([(d, d2), (d2, d)] if d != d2 else [(d, d2)]): bc = p // (s + 2) if p % (s + 2) == 0 and bc & 1 == t & 1 and bc > t: #print(s, t, p, q) ans += 1 d += 1 print(ans)