import sys from math import floor,sqrt sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) t = I() for _ in range(t): S,T = MI() U = 2*S**2 if U % T != 0 or T % 2 == 1: print(0) continue ANS = set() U //= T for d in range(1,int(U**(1/3))+1): if U % d == 0: c = T//2-d if c <= 0 or c > 10**9: break V = U//d p = T//2+d q = V+T//2*d if p**2-4*q < 0: continue a = floor((p-sqrt(p**2-4*q))//2) if 0 < a <= 10**9: b = p-a if 0 < b <= 10**9: if a*b == q: ans = [a,b,c] ans.sort() ANS.add(tuple(ans)) print(len(ANS)) for ans in ANS: a,b,c = ans print(a,b,c)