#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; //const bool debug = false; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; long long cheker(long long n) { if (n < 0)return -1; for (long long i = max((double)0, sqrt(n) - 10); i <= sqrt(n) + 10; ++i) { if (i * i == n)return i; } return -1; } ll sq(ll n) { ll ng = -1, ok = 3 * 1e9; while (abs(ng - ok) > 1) { ll mid = (ok + ng) / 2; if (mid * mid >= n)ok = mid; else ng = mid; } if (ok * ok == n)return ok; else return -1; } struct Miller { const vector v = { 2 , 7 , 61 }; // < 4,759,123,141 // x^k (mod m) long long modpow(long long x, long long k, long long m) { long long res = 1; while (k) { if (k & 1) { res = res * x % m; } k /= 2; x = x * x % m; } return res; } // check if n is prime bool check(long long n) { if (n < 2) { return false; } long long d = n - 1; long long s = 0; while (d % 2 == 0) { d /= 2; s++; } for (long long a : v) { if (a == n) { return true; } if (modpow(a, d, n) != 1) { bool ok = true; for (long long r = 0; r < s; r++) { if (modpow(a, d * (1LL << r), n) == n - 1) { ok = false; break; } } if (ok) { return false; } } } return true; } }; struct Rho { mt19937 mt; Miller miller; long long c; Rho() { mt.seed(clock()); } inline long long f(long long x, long long n) { return (x * x + c) % n; } long long check(long long n) { if (n == 4) { return 2; } c = mt() % n; long long x = mt() % n; long long y = x; long long d = 1; while (d == 1) { x = f(x, n); y = f(f(y, n), n); d = gcd(abs(x - y), n); } if (d == n) { return -1; } return d; } vector factor(long long n) { if (n <= 1) { return {}; } if (miller.check(n)) { return { n }; } long long res = -1; while (res == -1) { res = check(n); } vector fa = factor(res); vector fb = factor(n / res); fa.insert(fa.end(), fb.begin(), fb.end()); return fa; } }; Rho rho; void dfs(const map& f, ll num, const map::iterator &ite, vector &d) { if (ite == f.end()) { d.push_back(num); return; } rep(i, ite->second + 1) { dfs(f, num, next(ite), d); num *= ite->first; } } vector divisor(ll n) { map mp; for (const auto& aa : rho.factor(n))++mp[aa]; vectorret; dfs(mp, 1, mp.begin(), ret); return ret; } vector create(long long x) { vectorv; for (long long i = 1; i*i*i <= x; ++i) { if (0 == (x % i))v.push_back(i); } return v; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int q; cin >> q; while (q--) { long long s, t; cin >> s >> t; long long r = s * s * 16; if (0 != r % t) { cout << 0 << endl; continue; } r /= t; //vectorvx = divisor(r); vectorvx = create(r); sort(all(vx)); //r = x*y*(t-x-y) vector>>ans; rep(i, vx.size()) { long long x = vx[i]; long long rx = r / x; //rx = y(t-x-y) //y=((t-x)Âħsqrt((x-t)^2-4*rx))/2 long long sq = cheker((x - t) *(x - t) - 4 * rx); if (-1 == sq)continue; if (0 != abs(t - x - sq) % 2)continue; rep(j, 2) { long long y = (t - x - sq) / 2; if (1 == j) (t - x + sq) / 2; if (y > 0) { long long z = t - x - y; if (z > 0) { if ((0 == (abs(x - y) % 2)) && (0 == (abs(x - z) % 2))) { vectorabc(3); abc[0] = (x + y) / 2; abc[1] = (x + z) / 2; abc[2] = (y + z) / 2; sort(all(abc)); ans.push_back({ abc[0],{abc[1],abc[2]} }); //cout << abc[0] << abc[1] << abc[2] << endl; } } } } } sort(all(ans)); ans.erase(unique(all(ans)), ans.end()); cout << ans.size() << endl; for (auto abc : ans) { cout << abc.first << " " << abc.second.first << " " << abc.second.second << endl; } } return 0; }