#include int main(){ using namespace std; unsigned long S; cin >> S; const auto& calc = [&](auto X, auto Y) -> unsigned long { unsigned long ret{0}; // A is even if(2 * X < Y)ret += 100000000 / Y; // A is odd if(2 * X > Y)return ret; for(unsigned long i{3}; i * i <= Y; ++i){ if(Y % i == 0){ if(i & 1){ unsigned long k{(i + 1) / 2}, l{Y / i * k * (k - 1)}; ret += l % X == 0 && l / X <= 100000000; } if((Y / i) & 1){ unsigned long k{(Y / i + 1) / 2}, l{i * k * (k - 1)}; ret += l % X == 0 && l / X <= 100000000; } } } return ret; }; for(unsigned long i{0}, X, Y; i < S; ++i){ cin >> X >> Y; cout << calc(min(X, Y - X), Y) << endl; } return 0; }