#include using namespace std; #define rep(i,n) for(ll i=0;i<(n);i++) using ll = long long; bool f(ll x, ll y) { if (x / y > 0 && x % y == 0) return true; else return false; } void solve() { ll x, y; cin >> x >> y; if (x < y) swap(x, y); ll cnt = 0; for (ll i = 1; i * i <= x - y; i++) { if ((x - y) % i == 0) { { ll a = i + 1; ll div = (a + 1) * (a - 1); ll b = a * x - y, c = a * y - x; if (f(b, div) && f(c, div)) { cnt++; } } { ll a = (x - y) / i + 1; ll div = (a + 1) * (a - 1); ll b = a * x - y, c = a * y - x; if (f(b, div) && f(c, div)) { cnt++; } } } } cout << cnt << endl; } int main() { ll t; cin >> t; rep(i, t) solve(); return 0; }