#include <bits/stdc++.h>

using ll = long long;
ll x, y;

void subsolve() {
    ll ans = 0;
    for(int i = 1; i * i <= x; ++i) {
        if(i * i > x)
            break;
        if(x % i)
            continue;
        if(x / i > 1)
            ans += 1;
        if(x != i * i && x / (x / i) > 1)
            ans += 1;
    }
    ans += x;
    printf("%lld\n", ans);
}

void solve() {
    scanf("%lld%lld", &x, &y);
    if(x == y) {
        subsolve();
        return;
    }
    if(x < y)
        std::swap(x, y);
    ll ans = 0;
    auto check = [&](ll a) {
        if(a >= 2 && (x + y) % (a + 1) == 0 && (x - y) % (a - 1) == 0) {
            ll bpc = (x + y) / (a + 1);
            ll bmc = (x - y) / (a - 1);
            ll b = (bpc + bmc) / 2;
            ll c = x - a * b;
            if(b > 0 && c > 0 && a * c + b == y)
                ans += 1;
        }
    };
    for(ll u = 1; u * u <= x - y; ++u) {
        if((x - y) % u)
            continue;
        check(u + 1);
        if((x - y) != u * u)
            check((x - y) / u + 1);
    }
    printf("%lld\n", ans);
}

int main() {
    int t;
    scanf("%d", &t);
    for(int i = 0; i < t; ++i) {
        solve();
    }
    return 0;
}