#include int main(){ using namespace std; unsigned long S; cin >> S; const auto& calc = [&](auto X, auto Y) -> unsigned long { if(2 * X >= Y)return 0; unsigned long ret{0}; ret += 100000000 / Y; for(unsigned long i{1}; i * i <= Y; ++i){ if(Y % i == 0){ if(i & 1){ unsigned long l{Y * (i + 1) * (i - 1) / (2 * i)}; ret += l && l % X == 0 && l / X <= 100000000; } if(i * i < Y && (Y / i) & 1){ unsigned long l{i * (Y / i + 1) * (Y / i - 1) / 2}; if(static_cast<__int128>(i) * (Y / i + 1) * (Y / i - 1) / 200000000 > X)continue; ret += l && 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; }