#include using namespace std; int main() { int s; scanf("%d", &s); for (int z = 0; z < s; ++z) { int x, y; scanf("%d%d", &x, &y); if (x == y) { int ans = x-1; for (int i = 1; i*i <= x; ++i) { if (x%i != 0) continue; if (i > 2) ans++; if (i*i < x and x/i > 2) ans++; } printf("%d\n", ans); continue; } if (x < y) swap(x, y); int ans = 0; for (int i = 1; i*i <= x-y; ++i) { if ((x-y) % i != 0) continue; if ((x+y) % (i+2) == 0) { int p = (x-y) / i; int q = (x+y) / (i+2); if (p < q and p%2 == q%2) ans++; } if (i*i == x-y) continue; int j = (x-y)/i; if ((x+y) % (j+2) == 0) { int p = (x-y) / j; int q = (x+y) / (j+2); if (p < q and p%2 == q%2) ans++; } } printf("%d\n", ans); } return 0; }