#include using namespace std; typedef long long ll; typedef pair p_ll; template void debug(T itr1, T itr2) { auto now = itr1; while(now=0; i--) #define popcount __builtin_popcount const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; ll gcd(ll a, ll b) { if (a rho_algorithm(ll N, bool st=true) { if (N==1) return {}; repr(i,2,min(N,10ll)) { ll x = i, y = i, d = 1; if (N%x==0) d = x; else { bool ok = true; while (gcd(d,N)==1) { x = (x*x+1) % N; rep(i,2) y = (y*y+1) % N; d = gcd(abs(x-y),N); if (d==N) ok = false; } if (!ok) continue; } vector result = rho_algorithm(N/d,false); vector r2 = rho_algorithm(d,false); for (auto x: r2) result.push_back(x); if (st) sort(all(result)); return result; } return {N}; } int main() { ll t; cin >> t; assert(1<=t&&t<=20); rep(_,t) { ll S, T; cin >> S >> T; assert(1<=S&&S<=75ll*pow(10,7)); assert(3<=T&&T<=3ll*pow(10,9)); if ((16ll*S*S)%T) { cout << 0 << endl; continue; } ll R = 16ll*S*S/T; // cout << R << endl; vector soin = rho_algorithm(R); map ms; for (auto x: soin) ms[x]++; vector divisors = {1}; for (auto x: ms) { vector tdiv = divisors; for (auto y: divisors) { ll ny = y; rep(i,x.second) { ny *= x.first; tdiv.push_back(ny); } } divisors = tdiv; } sort(all(divisors)); // debug(all(divisors)); set> result; for (auto x: divisors) { if ((T-x)%2||T<=x) continue; ll b2mac = ((T-x)/2)*((T-x)/2) - R/x; if (pow((ll)sqrt(b2mac),2)!=b2mac) continue; ll y = (T-x)/2 + sqrt(b2mac), z = (T-x)/2 - sqrt(b2mac); if ((T-y)%2) continue; vector r = {(T-x)/2, (T-y)/2, (T-z)/2}; sort(all(r)); result.insert(r); } cout << result.size() << endl; for (auto x: result) debug(all(x)); } return 0; }