#include #include using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) {a = max(a, b);} template void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; map factorize(long long x) { map ret; for(long long p = 2; p * p <= x; p++) { int cnt = 0; while(x % p == 0) x /= p, cnt++; if (cnt) ret[p] = cnt; } if (x > 1) ret[x] = 1; return ret; } VL divisors(vector> fs) { VL ret{1}; for(auto [p, cnt]: fs) { ll now = 1; const int sz = ret.size(); for(int i = 1; i <= cnt; i++) { now *= p; rep(j, sz) ret.push_back(ret[j] * now); } } sort(all(ret)); return ret; } void solve() { ll s, t; cin >> s >> t; const ll Z = s * s * 16 / t; auto fs = factorize(s); for(auto& [k, v]: fs) v *= 2; fs[2] += 4; auto ft = factorize(t); for(auto [k, v]: ft) fs[k] -= v; vector> factors; for(auto [k, v]: fs) { if (v < 0) { cout << 0 << '\n'; return; } if (v) factors.emplace_back(k, v); } auto divs = divisors(factors); int sz = divs.size(); vector> ans; rep(i, sz) rep(j, sz) { ll ta = divs[i], tb = divs[j]; if (ta >= t || tb >= t) continue; __int128_t x = 1; x *= ta; x *= tb; if (Z % x != 0) continue; ll tc = Z / x; if (tc >= t) continue; ll a = t - ta, b = t - tb, c = t - tc; if (a % 2 || b % 2 || c % 2) continue; a /= 2, b /= 2, c /= 2; if (abs(a - b) < c && c < abs(a + b)) { ans.emplace_back(a, b, c); } } cout << ans.size() << '\n'; for(auto [a, b, c]: ans) { cout << a << ' ' << b << ' ' << c << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while(tt--) solve(); }