mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline for _ in range(int(input())): N, T = map(int, input().split()) if T & 2 == 0: print("Yes") for i in range(1, N+1): for j in range(i+1, N+1): if i == 1: print(i, j, T // 2) else: print(i, j, 0) else: if N <= 3: print("Yes") for i in range(1, N+1): for j in range(i+1, N+1): if i == 1 and j == 2: print(i, j, T) else: print(i, j, 0) elif N & 1: if T >= N: T -= N print("Yes") for i in range(1, N + 1): for j in range(i + 1, N + 1): if i == 1: print(i, j, T // 2 + 1) else: print(i, j, 1) else: print("No") else: print("No") if __name__ == '__main__': main()