#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
    int tsz;
    cin >> tsz;
    rep(_, tsz) {
        int x, y;
        cin >> x >> y;
        if (x < y) swap(x, y);
        int p = x + y, q = x - y;
        int d = 1;
        int ans = 0;
        while(d * d <= q) {
            if (q % d == 0) {
                int d2 = q / d;
                rep(_, d == d2 ? 1 : 2) {
                    int s = d + 2, bc = p / s;
                    ans += p % s == 0 && (bc & 1) == (d2 & 1) && bc > d2;
                    swap(d, d2);
                }
            }
            d += 1;
        }
        cout << ans << endl;
    }
}