mod = 1000000007 eps = 10**-9 NMAX = 10**5 def main(): import sys input = sys.stdin.readline for _ in range(int(input())): S, T = map(int, input().split()) if T & 1: print(0) continue t = T // 2 if (S * S) % t: print(0) continue U = S * S // t ans = [] for A in range(1, NMAX): if (t - A) * 2 >= T: continue if A ** 3 > U: break if U % A: continue for B in range(A, NMAX): if A * B * B > U: break if U % (A * B) == 0: C = U // (A * B) a = t - A b = t - B c = t - C if a + b + c == T and a < b + c: ans.append((a, b, c)) print(len(ans)) for a, b, c in ans: print(a, b, c) if __name__ == '__main__': main()