mod = 1000000007 eps = 10**-9 NMAX = 10**5 def main(): import sys from math import sqrt 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 alpha = t - A beta = U // A D = alpha ** 2 - 4 * beta if D >= 0: d = int(sqrt(D) + 0.1) if d ** 2 == D: if alpha & 1 == d & 1: B = (alpha + d) // 2 C = (alpha - d) // 2 a = t - A b = t - B c = t - C if a + b + c == T and a < b + c and max(a, b, c) == a: ans.append((a, b, c)) print(len(ans)) for a, b, c in ans: print(a, b, c) if __name__ == '__main__': main()