def divisor_list(N): #約数のリスト if N == 1: return [1] res = [] for i in range(1,N): if i*i >= N: break if N%i == 0: res.append(i) res.append(N//i) if i*i == N: res.append(i) return sorted(res) def solve(n,t): if t%2: return [] t //= 2 N = n*n div = divisor_list(N) # pqr(p+q+r) = n*n なる (p,q,r)を求める ans = 0 L = len(div) res = [] for i,p in enumerate(div): if p*p > n: break for j in range(i,L): q = div[j] if p*q*q*(p+q+q) > N: break if N%(p*q): continue r = t-p-q if r*t == N//p//q: res.append((p,q,r)) return res T = int(input()) for _ in range(T): s,t = map(int,input().split()) r = solve(s,t) print(len(r)) for a,b,c in r: print(a+b,b+c,c+a)