#include //#include #define int long long #define rep(i,a) for (int i = 0; i < (a); i++ ) #define Rep(i,start,a) for (int i = start; i < (a); i++ ) #define ALL(vec) (vec).begin(), (vec).end() #define Sort(vec) sort((vec).begin(), (vec).end()) // 小さい順 #define SORT(vec) sort((vec).begin(), (vec).end(), [](auto a, auto b){return a>b;}) // 大きい順 #define SORTll(vec) sort((vec).begin(), (vec).end(), [](long long a, long long b){return a>b;}) // 大きい順 #define debug(x) cerr << #x << " = " << (x) << endl #define Bit(s,k) (s>>k)&1 #define VI vector #define VLL vector #define PII pair #define VPII vector #define VB vector #define VVI vector> #define VVVI vector>> #define Graph vector> #define PB emplace_back #define USI unordered_set #define Maze vector #define Pqueue priority_queue #define MP make_pair #define WeightedGraph vector>> // parent, (to, cost) #define vecdebug(vec) {cerr << #vec << " = [" ; for(auto x : (vec)){cerr << (x) << ", ";} cerr << "]" << endl; } #define vdebug(vec,i) cerr << #vec << "[" << (i) << "] = " << (vec)[(i)] << endl #define vvdebug(vec,i,j) cerr << #vec << "[" << (i) << "][" << (j) << "] = " << (vec)[(i)][(j)] << endl #define vvvdebug(vec,i,j,k) cerr << #vec << "[" << (i) << "][" << (j) << "][" << (k) <<"] = " << (vec)[(i)][(j)][(k)] << endl #define pdebug(p) cerr << #p << " = [" << (p).first << ", " << (p).second << "]" << endl typedef long long ll; typedef long double ld; const int mod = 998244353; const int MOD = 1000000007; const ll INFLL = (1LL << 60) -1; const int INF = (1 << 30) -1; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const long double pi = 2*asin(1); using namespace std; //using namespace atcoder; //using mint = modint1000000007; //using mint = modint998244353; //using mint = modint998244353; //using mint = static_modint<7>; template inline void chmin(T &x, T y){if(x>y) x=y;} template inline void chmax(T &x, T y){if(x= 'A' && X <= 'Z') return 26 + (int)(X-'A'); return (int)(X - 'a'); } inline int ctoi(char x){return (int)(x-'0');} template T Max(T x, T y){if(x>y) return x; return y;} template T Min(T x, T y){if(x inline T ABS(T n){if(n<0) return -n; return n;} ll GCD(ll a, ll b){if(a%b==0) return b; return GCD(b,a%b);} ll LCM(ll a, ll b){return a / GCD(a,b) *b;} vector divisors(int n){ vector ret; Rep(i,1,n+1){ if(i*i>n) break; if(i*i==n){ ret.PB(i); break; } if(n%i==0){ ret.PB(i); ret.PB(n/i); } } sort(ret.begin(), ret.end()); return ret; } void solve(){ int S,T; cin >> S >> T; if((4 * S * S) % T != 0){ cout << 0 << endl; return; } //debug("!"); set st; int val = 16 * S * S / T; if(val / (T * T) > 27 * T * T){ cout << 0 << endl; return; } debug(val / (T*T) - T*T); auto div = divisors(16 * S * S / T); //vecdebug(div); int sz = div.size(); rep(i,sz){ if(3 * div[i] > T) break; Rep(j,i,sz){ int x = div[i]; int y = div[j]; if(x + 2 * y > T) break; if((x + y) & 1) continue; if((T - x) & 1) continue; if(val / x == y * (T - x - y)) st.insert(MP(x,y)); } } cout << st.size() << endl; for(auto p : st){ int x = p.first; int y = p.second; int z = T - x - y; int a = (x + y) / 2; int b = (y + z) / 2; int c = (z + x) / 2; cout << a << " " << b << " " << c << endl; } } signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(16); int Query; cin >> Query; rep(_,Query) solve(); }