import sys input = sys.stdin.readline from collections import Counter def fact(x): sq=round(x**(0.5)) F=Counter() for i in range(2,sq+1): while x%i==0: F[i]+=1 x//=i if x>1: F[x]+=1 return F t=int(input()) for tests in range(t): S,s=list(map(int,input().split())) if s%2==1: print(0) continue k=s//2 if S*S%k!=0: print(0) continue u=S*S//k F=fact(S) kf=fact(k) for c in F: F[c]*=2 for c in kf: F[c]-=kf[c] #print(F) LIST=[1] for f in F: LIST2=[] c=F[f] for l in LIST: for i in range(1,c+1): if l*f**i=y and z in SET: ANS.append((x+y,y+z,z+x)) print(len(ANS)) for ans in ANS: print(*ans)