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