""" https://yukicoder.me/problems/no/1571 """ from sys import stdin import sys Q = int(stdin.readline()) for loop in range(Q): N,T = map(int,stdin.readline().split()) if T % 2 == 0: ans = [] for b in range(1,N+1): for a in range(1,b): if a == 1 or b == 1: ans.append((a,b,T//2)) else: ans.append((a,b,0)) print ("Yes") for i in ans: print (*i) else: if N % 2 == 0 or N == 2: print ("No") elif N == 3: ans = [(1,2,T),(2,3,0),(1,3,0)] print ("Yes") for i in ans: print (*i) elif T >= N: ans = [] rem = N - T for b in range(1,N+1): for a in range(1,b): if a == 1 or b == 1: ans.append((a,b,rem//2 + 1)) else: ans.append((a,b,1)) print ("Yes") for i in ans: print (*i) else: print ("No")