#include using namespace std; using ll = long long; void solve() { ll X, Y; cin >> X >> Y; if (X == Y) { ll ans = X - 1; ll t = 2; while (t * t <= X) { if (X % t == 0) { if (t * t == X) { ans++; } else { ans += 2; } } t++; } if (X > 1) { ans += 1; } cout << ans << "\n"; return; } if (X < Y) { swap(X, Y); } ll PN = X + Y; ll ans = 0; ll MN = X - Y; ll t = 1; while (t * t <= MN) { if (MN % t == 0) { ll n = MN / t; if (PN % (t + 2) == 0) { ll target = PN / (t + 2); if ((target + n) % 2 == 0 && target > n) { ans++; } } if (n == t) { t++; continue; } if (PN % (n + 2) == 0) { ll target = PN / (n + 2); if ((target + t) % 2 == 0 && target > t) { ans++; } } } t++; } cout << ans << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll S; cin >> S; for (int i = 0; i < S; i++) { solve(); } return 0; }