Phoenix has collected $n$ pieces of gold, and he wants to weigh them together so he can feel rich. The $i$-th piece of gold has weight $w_i$. All weights are distinct. He will put his $n$ pieces of gold on a weight scale, one piece at a time.

The scale has an unusual defect: if the total weight on it is exactly $x$, it will explode. Can he put all $n$ gold pieces onto the scale in some order, without the scale exploding during the process? If so, help him find some possible order.

Formally, rearrange the array $w$ so that for each $i$ $(1 \le i \le n)$, $\sum\limits_{j = 1}^{i}w_j \ne x$.


-----Input-----

The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases.

The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 100$; $1 \le x \le 10^4$) — the number of gold pieces that Phoenix has and the weight to avoid, respectively.

The second line of each test case contains $n$ space-separated integers $(1 \le w_i \le 100)$ — the weights of the gold pieces. It is guaranteed that the weights are pairwise distinct.


-----Output-----

For each test case, if Phoenix cannot place all $n$ pieces without the scale exploding, print NO. Otherwise, print YES followed by the rearranged array $w$. If there are multiple solutions, print any.


-----Examples-----

Input
3
3 2
3 2 1
5 3
1 2 3 4 8
1 5
5
Output
YES
3 2 1
YES
8 1 2 3 4
NO


-----Note-----

In the first test case, Phoenix puts the gold piece with weight $3$ on the scale first, then the piece with weight $2$, and finally the piece with weight $1$. The total weight on the scale is $3$, then $5$, then $6$. The scale does not explode because the total weight on the scale is never $2$.

In the second test case, the total weight on the scale is $8$, $9$, $11$, $14$, then $18$. It is never $3$.

In the third test case, Phoenix must put the gold piece with weight $5$ on the scale, and the scale will always explode.

Difficulty: EASY
Tags: Greedy algorithms

Mathematics

Constructive algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) == x:
		print('NO')
		continue
	l = []
	s = 0
	reject_list = []
	for i in range(n):
		s += arr[i]
		if s == x:
			reject_list.append(arr[i])
			s -= arr[i]
		else:
			l.append(arr[i])
	l.extend(reject_list)
	del reject_list, arr, n, x
	print('YES')
	print(' '.join(map(str, l)))


import os
import sys
from io import BytesIO, IOBase
import math
from collections import Counter

def func(n, x, array):
	c = 0
	switch = None
	for (i, val) in enumerate(array):
		c += val
		if c == x:
			switch = i
	if switch is not None:
		if switch == len(array) - 1:
			print('NO')
			return
		else:
			(array[switch], array[switch + 1]) = (array[switch + 1], array[switch])
	print('YES')
	print(' '.join((str(i) for i in array)))

def main():
	num_test = int(parse_input())
	result = []
	for _ in range(num_test):
		(n, x) = [int(i) for i in parse_input().split()]
		array = [int(i) for i in parse_input().split()]
		func(n, x, array)
parse_input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	if s == x:
		print('NO')
	else:
		print('YES')
		ll = []
		c = 0
		for i in l:
			c += i
			if c == x:
				c -= i
				ll.append(i)
			else:
				print(i, end=' ')
		for i in ll:
			print(i, end=' ')
		print()


def func(arr, n, x):
	s = 0
	for i in range(n):
		if s + arr[i] == x:
			if i != n - 1:
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
				print('YES')
				print(' '.join(map(str, arr)))
			else:
				print('NO')
			break
		elif s + arr[i] > x:
			print('YES')
			print(' '.join(map(str, arr)))
			break
		else:
			s += arr[i]
			if i == n - 1:
				print('YES')
				print(' '.join(map(str, arr)))
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	func(arr, n, x)


cases = int(input())
for i in range(0, cases):
	(n, x) = [int(i) for i in input().split()]
	numbers = [int(i) for i in input().split()]
	running = 0
	found = False
	for i in range(0, len(numbers)):
		running += numbers[i]
	if found:
		continue
	if running == x:
		print('NO')
	else:
		print('YES')
		running = 0
		for i in range(0, len(numbers)):
			if running + numbers[i] == x:
				temp = numbers[i + 1]
				numbers[i + 1] = numbers[i]
				numbers[i] = temp
			running += numbers[i]
		print(' '.join((str(p) for p in numbers)))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	s = 0
	flag = True
	for (i, val) in enumerate(w):
		s += val
		if s == x:
			if i == n - 1:
				flag = False
				break
			else:
				(w[i], w[i + 1]) = (w[i + 1], w[i])
				break
	if flag:
		print('YES')
		print(*w)
	else:
		print('NO')


t = int(input())
for i in range(t):
	(n, x) = [int(k) for k in input().split()]
	w = [int(k) for k in input().split()]
	delta = sum(w)
	if delta == x:
		print('NO')
	else:
		w.sort()
		res = 0
		c = []
		epsilon = 0
		for j in w:
			if res + j != x:
				res += j
				c.append(j)
			else:
				c.append(w[-1])
				res += w[-1]
				epsilon = j
		if sum(c) > delta:
			c[-1] = epsilon
		print('YES')
		print(' '.join([str(k) for k in c]))


def check(lst, n, x):
	total = 0
	for i in range(n):
		total += lst[i]
		if total == x:
			return False
	return True

def solve(n, x, lst):
	if sum(lst) == x:
		return 'NO'
	if len(set(lst)) == 1 and x % lst[0] == 0 and (sum(lst) >= x):
		return 'NO'
	ok = False
	for i in range(n):
		if check(lst, n, x):
			ok = True
			break
		else:
			lst = lst[-1:] + lst[:-1]
	if not ok:
		return 'NO'
	print('YES')
	return ' '.join(map(str, lst))
for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	print(solve(n, x, lst))


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	weights = list(map(int, input().split()))
	sum = 0
	sums = []
	for i in range(n):
		sum += weights[i]
		sums.append(sum)
	if sum == x:
		print('NO')
	else:
		print('YES')
		for i in range(n):
			if sums[i] == x:
				temp = weights[i]
				weights[i] = weights[i + 1]
				weights[i + 1] = temp
			print(weights[i], end=' ')
		print('')


def main():
	for _ in range(int(input())):
		(n, x) = map(int, input().split())
		arr = list(map(int, input().split()))
		print(get(arr, x))

def get(arr, x):
	k = 0
	arr = list(sorted(arr, reverse=True))
	for i in range(len(arr)):
		if k + arr[i] == x:
			found = True
			for j in range(i, len(arr)):
				if k + arr[j] != x:
					b = arr[j]
					y = arr[i]
					arr[i] = b
					arr[j] = y
					found = False
			if found:
				return 'NO'
			k += arr[i]
		else:
			k += arr[i]
	return 'YES' + '\n' + ' '.join(map(str, arr))
main()


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
pr = lambda x: x

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
import random

def solve():
	for _ in range(int(input())):
		(n, x) = aj()
		A = aj()
		flag = 1
		for i in range(10):
			X = []
			c = 0
			flag = 1
			for i in A:
				c += i
				if c == x:
					flag = 0
					break
			if flag == 1:
				break
			random.shuffle(A)
		if flag:
			Y(1)
			print(*A)
		else:
			Y(0)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	from aj import *
except:
	pass
solve()


from sys import stdin
from collections import deque

def readGenerator():
	while True:
		tokens = stdin.readline().strip().split(' ')
		for t in tokens:
			yield t
reader = readGenerator()

def readWord():
	return next(reader)

def readInt():
	return int(next(reader))

def readFloat():
	return float(next(reader))

def readLine():
	return input()

def solve(n, x, w):
	a = []
	s = 0
	i = 0
	j = n - 1
	while j - i >= 0:
		if s + w[i] != x:
			s += w[i]
			a.append(str(w[i]))
			i += 1
		elif s + w[j] != x:
			s += w[j]
			a.append(str(w[j]))
			j -= 1
		else:
			break
	if len(a) != n:
		print('NO')
	else:
		print('YES')
		print(' '.join(a))
t = readInt()
for _ in range(t):
	(n, x) = (readInt(), readInt())
	w = [readInt() for _ in range(n)]
	solve(n, x, w)


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	(n, k) = mp()
	l = li()
	l.sort()
	s = sum(l)
	if s == k:
		pr('NO')
		return
	ind = -1
	ans = []
	x = 0
	for i in range(n):
		if x + l[i] == k:
			ind = i
		else:
			ans.append(l[i])
			x += l[i]
	if ind != -1:
		ans.append(l[ind])
	pr('YES')
	print(*ans)
for _ in range(inp()):
	solve()


for enumeration in range(int(input())):
	(n, x) = [int(x) for x in input().split()]
	array = list(sorted([int(x) for x in input().split()]))
	temp = 0
	for i in range(n):
		temp += array[i]
		if temp == x and i < n - 1:
			(array[i], array[i + 1]) = (array[i + 1], array[i])
	if temp == x:
		print('NO')
	else:
		print('YES')
		print(' '.join([str(x) for x in array]))


def check(n, x, l1):
	l2 = []
	l3 = []
	tot = 0
	for i in l1:
		tot += i
		if tot == x:
			tot -= i
			l3.append(i)
		else:
			l2.append(i)
	l4 = l2 + l3
	print('YES')
	for i in l4:
		print(i, end=' ')
	print()
t = int(input())
while t > 0:
	(n, x) = map(int, input().strip().split())
	l1 = list(map(int, input().strip().split()))
	l1.sort()
	if sum(l1) == x:
		print('NO')
	else:
		check(n, x, l1)
	t -= 1


t = int(input())
while t > 0:
	l = input().split()
	n = int(l[0])
	x = int(l[1])
	lst = [int(p) for p in input().split()]
	ind = 0
	ps = 0
	if sum(lst) == x:
		print('NO')
		t -= 1
		continue
	i = 0
	while i < len(lst):
		ps = sum(lst[:i + 1])
		if ps == x:
			tp = lst[i]
			lst.remove(lst[i])
			lst.append(tp)
		else:
			i += 1
	print('YES')
	for j in lst:
		print(j, end=' ')
	t -= 1


def solve():
	(n, x) = [int(x) for x in input().strip().split()]
	weights = [int(x) for x in input().strip().split()]
	all_weights = sum(weights)
	if all_weights == x:
		return (False, [])
	(swap_index, partial_sum) = (-1, 0)
	for (index, w) in enumerate(weights):
		if partial_sum + w == x:
			swap_index = index
			break
		partial_sum += w
	if swap_index == -1:
		return (True, weights)
	(sw1, sw2) = (swap_index, swap_index + 1)
	if sw2 == n:
		(sw1, sw2) = (swap_index - 1, swap_index)
	tmp = weights[sw1]
	weights[sw1] = weights[sw2]
	weights[sw2] = tmp
	return (True, weights)
for _ in range(int(input())):
	(possible, items) = solve()
	if possible:
		print('YES')
		print(' '.join((str(w) for w in items)))
	else:
		print('NO')


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	(n, x) = input_split()
	weights = input_split()
	weights.sort()
	if sum(weights) == x:
		print('NO')
		continue
	s = 0
	for i in range(n):
		s += weights[i]
		if s == x:
			(weights[i], weights[i + 1]) = (weights[i + 1], weights[i])
			break
	print('YES')
	print(*weights, sep=' ')


def inpl():
	return list(map(int, input().split()))

def inpi():
	return int(input())

def f():
	(n, x) = inpl()
	w = inpl()
	w.sort()
	if sum(w) == x:
		print('NO')
		return
	print('YES')
	for i in range(1, n):
		if sum(w[:i]) == x:
			(w[i - 1], w[i]) = (w[i], w[i - 1])
			break
	print(' '.join((str(c) for c in w)))
t = int(input())
for _ in range(t):
	f()


import sys

def get_ints():
	return list(map(int, sys.stdin.readline().strip().split()))
testcases = int(input())
for testcase in range(testcases):
	temparr = get_ints()
	n = temparr[0]
	x = temparr[1]
	arr = get_ints()
	totalsum = sum(arr)
	if totalsum == x:
		print('NO')
		continue
	arr = sorted(arr)
	skip = []
	curtotal = 0
	ans = []
	for elem in arr:
		if elem + curtotal != x:
			ans.append(str(elem))
			curtotal += elem
		else:
			skip.append(elem)
	flag = 0
	while len(skip):
		elem = skip[-1]
		if elem + curtotal != x:
			curtotal += elem
			ans.append(str(elem))
			skip.pop()
		else:
			flag = 1
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')
		print(' '.join(ans))


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, log2
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0

def def_inf():
	return inf

def atoi(s):
	return ord(s) - ord('0')

def inc(s, n=1):
	return chr((ord(s) - ord('a') + n) % 26 + ord('a'))

class XY:

	def __init__(self, x, y):
		self.x = x
		self.y = y

def rotate(a, b, c):
	ang = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y)
	if ang == 0:
		return 0
	else:
		return ang / abs(ang)

def phi(n):
	(res, p) = (n, 2)
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			res -= res // p
		p += 1
	if n > 1:
		res -= res // n
	return res
for _ in range(iinp()):
	(n, x) = mp()
	a = lmp()
	a.sort()
	if sum(a) == x:
		print('NO')
	else:
		sm = 0
		j = -1
		for i in range(n):
			sm += a[i]
			if sm == x:
				j = i
				break
		if j != -1:
			(a[j], a[j + 1]) = (a[j + 1], a[j])
		print('YES')
		print(*a)


def mapit():
	temp = list(map(int, input().split()))
	return temp

def solution():
	(n, x) = mapit()
	w = mapit()
	w.sort()
	sm = [0] * n
	sm[0] = w[0]
	for i in range(1, n):
		sm[i] += sm[i - 1] + w[i]
	if sm[-1] == x:
		print('NO')
		return
	if sm[-1] < x or sm[0] > x:
		print('YES')
		print(*w)
		return
	idx = 'False'
	for i in range(n):
		if sm[i] == x:
			idx = i
			break
	if idx == 'False':
		print('YES')
		print(*w)
	else:
		(w[idx], w[idx + 1]) = (w[idx + 1], w[idx])
		print('YES')
		print(*w)
	return
t = int(input())
while t:
	t -= 1
	solution()


T = int(input())
for t in range(T):
	(n, x) = tuple([int(x) for x in input().split()])
	w = [int(x) for x in input().split()]
	w = sorted(w)
	sum_w = sum(w)
	if x == sum_w:
		print('NO')
	else:
		result_w = []
		cur_sum = 0
		have_added = set()
		for (i, wi) in enumerate(w):
			if wi in have_added:
				continue
			if cur_sum + wi != x:
				result_w.append(wi)
				cur_sum += wi
				have_added.add(wi)
			else:
				result_w.append(w[i + 1])
				result_w.append(wi)
				cur_sum += wi + w[i + 1]
				have_added.add(wi)
				have_added.add(w[i + 1])
		print('YES')
		print(' '.join([str(x) for x in result_w]))


t1 = int(input())
for _ in range(t1):
	(n, x) = map(int, input().split())
	p = 0
	o = 0
	a = list(map(int, input().split()))
	t = ''
	if sum(a) != x:
		for i in a:
			if o == 1:
				t += str(i) + ' ' + str(b) + ' '
				p += i + b
				o = 0
			elif p + i != x:
				p += i
				t += str(i) + ' '
			else:
				b = i
				o = 1
		print('YES')
		print(t[:-1])
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	weight = list(map(int, input().split()))
	prefix = []
	res = []
	s1 = 0
	for i in range(n):
		s2 = s1 + weight[i]
		if s2 == x:
			res.append(weight[i])
		else:
			prefix.append(weight[i])
			s1 = s2
	prefix += res
	s1 = 0
	found = True
	for i in range(n):
		s1 += prefix[i]
		if s1 == x:
			found = False
			break
	if not found:
		print('NO')
	else:
		print('YES')
		print(' '.join(map(str, prefix)))


t = int(input())
for i in range(t):
	(n, x) = [int(a) for a in input().split()]
	l = [int(a) for a in input().split()]
	d = 0
	for j in l:
		if j == x:
			d += 1
	if d == n:
		print('NO')
	elif sum(l) == x:
		print('NO')
	else:
		print('YES')
		c = 0
		s = 0
		l1 = []
		while c < n:
			s += l[c]
			if s != x:
				print(l[c], end=' ')
			else:
				l1.append(c)
				s -= l[c]
			c += 1
		for j in l1:
			print(l[j], end=' ')
		print()


test_cases = int(input())
for test_case in range(1, test_cases + 1):
	(number_of_pieces, unnecessary_weight) = list(map(int, input().split()))
	pieces = sorted(list(map(int, input().split())), reverse=True)
	if sum(pieces) == unnecessary_weight:
		print('NO')
	else:
		index = 0
		result = []
		current_sum = 0
		whole_sum = sum(pieces)
		while index < len(pieces):
			if current_sum > unnecessary_weight:
				break
			if current_sum + pieces[index] == unnecessary_weight:
				index += 1
				continue
			current_sum += pieces[index]
			result.append(pieces.pop(index))
		if current_sum > unnecessary_weight:
			result += pieces
			current_sum += sum(pieces)
			pieces = []
		if pieces:
			if current_sum + sum(pieces) == whole_sum and current_sum != unnecessary_weight:
				result += pieces
				current_sum += sum(pieces)
				pieces = []
		if current_sum == whole_sum:
			print('YES')
			print(' '.join(map(str, result)))
		else:
			print('NO')


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	curr = 0
	l = []
	for _ in range(n):
		for i in range(len(w)):
			if curr + w[i] != x:
				curr += w[i]
				l.append(w[i])
				w.pop(i)
				break
	if len(w) > 0:
		print('NO')
	else:
		print('YES')
		print(*l)


t = int(input())
for _ in range(t):
	i = [int(k) for k in input().strip().split()]
	(n, x) = (i[0], i[1])
	w = [int(k) for k in input().strip().split()]
	w.sort()
	flag = True
	for (i, val) in enumerate(w):
		x -= val
		if x == 0:
			try:
				(w[i], w[i + 1]) = (w[i + 1], w[i])
			except IndexError:
				flag = False
			finally:
				break
	if flag:
		print('YES')
		print(' '.join((str(i) for i in w)))
	else:
		print('NO')


tests = int(input())
for test in range(tests):
	(n, x) = map(int, input().split())
	w = [int(x) for x in input().split()]
	if x == sum(w):
		print('NO')
	else:
		print('YES')
		s = 0
		i = 0
		while i < n - 1:
			if x == s + w[i]:
				(w[i], w[i + 1]) = (w[i + 1], w[i])
			s += w[i]
			i += 1
		print(*w, sep=' ')


tests = int(input())
for t in range(0, tests):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if x == sum(a):
		print('NO')
	else:
		print('YES')
		output = ''
		count = 0
		for i in range(0, len(a)):
			if x == count + a[i]:
				temp = a[i]
				a[i] = a[i + 1]
				a[i + 1] = temp
			count += a[i]
		output = ''
		for i in a:
			output += str(i) + ' '
		print(output[:-1])


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	w = list(map(int, input().split()))
	if sum(w) == x:
		print('NO')
	else:
		prefix = 0
		same = True
		w.sort()
		for i in range(len(w) - 1):
			prefix += w[i]
			if prefix == x:
				(w[i], w[i + 1]) = (w[i + 1], w[i])
				break
		print('YES')
		print(' '.join(list(map(str, w))))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	if sum(lst) == x:
		print('No')
	else:
		c = 0
		for i in range(n):
			c += lst[i]
			if c == x:
				(lst[i], lst[i + 1]) = (lst[i + 1], lst[i])
		print('YES')
		print(' '.join(map(str, lst)))


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	curr = 0
	if sum(arr) == K:
		print('NO')
	else:
		for i in range(N - 1):
			curr += arr[i]
			if curr == K:
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
				break
		print('YES')
		print(' '.join([str(i) for i in arr]))


t = int(input())
while t:
	t = t - 1
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	final = []
	flag = [False] * n
	l.sort()
	s = 0
	for i in range(n):
		if s + l[i] != x:
			s += l[i]
			final.append(l[i])
			flag[i] = True
	for i in range(n):
		if s + l[i] != x and flag[i] == False:
			s += l[i]
			final.append(l[i])
			flag[i] = True
	f = 0
	for i in range(n):
		if flag[i] == False:
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		print('YES')
		print(*final)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	b = a.copy()
	c = a.copy()
	b.sort()
	c.sort(reverse=True)
	tot = sum(a)
	if tot == x:
		print('NO')
	else:
		totb = 0
		bver = True
		print('YES')
		pos = -1
		for i in range(n):
			totb += b[i]
			if totb == x:
				pos = i + 1
				bver = False
				break
		if bver == True:
			print(*b)
		else:
			totc = 0
			cver = True
			for i in range(n):
				totc += c[i]
				if totc == x:
					cver = False
			if cver == True:
				print(*c)
			else:
				ans = []
				for i in range(1, pos):
					ans.append(b[i])
				for i in range(pos, n):
					ans.append(b[i])
				ans.append(b[0])
				print(*ans)


from sys import stdin
input = stdin.buffer.readline
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	arr.sort()
	s = 0
	ans = []
	flag = True
	keep = None
	for i in range(n):
		s = s + arr[i]
		if s == x:
			if i < n - 1:
				keep = arr[i]
			else:
				flag = False
				break
		else:
			ans.append(arr[i])
	if flag:
		print('YES')
		if keep != None:
			ans.append(keep)
		print(*ans)
	else:
		print('NO')


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	cnt = 0
	for i in range(n):
		if cnt + w[i] == x:
			if n == 1:
				print('NO')
				break
			elif i < n - 1:
				(w[i], w[i + 1]) = (w[i + 1], w[i])
			else:
				print('NO')
				break
		cnt += w[i]
	else:
		print('YES')
		print(*w)


count = int(input())
for i in range(count):
	num_x = input().split()
	x = int(num_x[1])
	num = int(num_x[0])
	num_list = input().split()
	for j in range(num):
		num_list[j] = int(num_list[j])
	num_list.sort()
	sum_num = 0
	for q in range(num):
		sum_num += num_list[q]
	if x == sum_num:
		print('NO')
	elif x > sum_num:
		print('YES')
		for q in range(len(num_list)):
			print('{}'.format(num_list[q]), end=' ')
		print('\n')
	else:
		sum_i = 0
		print('YES')
		for s in range(len(num_list)):
			sum_i += num_list[s]
			if sum_i == x:
				t = num_list[s]
				num_list[s] = num_list[s + 1]
				num_list[s + 1] = t
				break
		for q in range(len(num_list)):
			print('{}'.format(num_list[q]), end=' ')
		print('\n')


t = int(input())
while t > 0:
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	sum = 0
	f = 0
	for i in range(0, len(arr)):
		sum += arr[i]
		if sum == x:
			if i + 1 < n:
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
			else:
				f = 1
	if not f:
		print('YES')
		for ele in arr:
			print(ele, end=' ')
		print()
	else:
		print('NO')
	t -= 1


import sys
input = sys.stdin.readline
t = int(input())
while t > 0:
	t -= 1
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) == x:
		print('NO')
	else:
		print('YES')
		ans = []
		su = 0
		while a:
			y = a.pop(0)
			if su + y != x:
				su += y
				ans.append(y)
			else:
				a.append(y)
		print(*ans)


def check(w, x):
	s = 0
	for i in w:
		s += i
		if s == x:
			return False
	return True
tc = int(input())
for _ in range(tc):
	(n, x) = map(int, input().split())
	w = [int(i) for i in input().split()]
	if sum(w) == x:
		print('NO')
		continue
	w.sort()
	if check(w, x):
		print('YES')
		print(*w)
		continue
	for i in range(n - 1):
		ktemp = w[n - i - 1:] + w[:n - i - 1]
		if check(ktemp, x):
			print('YES')
			print(*ktemp)
			break


def solve(arr, x):
	if sum(arr) == x:
		print('NO')
		return
	arr.sort()
	n = len(arr)
	if arr[0] == arr[-1]:
		if x % arr[0] == 0 and x // arr[0] <= n:
			print('NO')
			return
	total = 0
	pre = 0
	print('YES')
	for (i, a) in enumerate(arr):
		total += a
		if a != arr[-1]:
			pre = i
		if total == x:
			(arr[pre], arr[-1]) = (arr[-1], arr[pre])
			break
	print(*arr)
	return
for _ in range(int(input())):
	(_, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	solve(arr, x)


t = int(input())
while t > 0:
	(n, x) = map(int, input().split())
	info = list(map(int, input().split()))
	if sum(info) == x:
		print('NO')
		t -= 1
		continue
	for i in range(n):
		if x == info[i]:
			(info[i], info[i + 1]) = (info[i + 1], info[i])
		x -= info[i]
	print('YES')
	print(' '.join(map(str, info)))
	t -= 1


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	if sum(a) == y:
		print('NO')
	else:
		for j in range(x):
			s = s + a[j]
			if s == y:
				(a[j], a[j + 1]) = (a[j + 1], a[j])
		print('YES')
		print(*a)


def main():
	t = int(input())
	for _ in range(1, t + 1):
		(n, x) = map(int, input().split())
		ws = list(map(int, input().split()))
		res = codeforces(ws, x)
		if res:
			print('YES')
			print(' '.join(map(str, res)))
		else:
			print('NO')

def codeforces(ws, x):
	sum = 0
	res = []
	while ws:
		if sum + ws[0] == x:
			if len(ws) > 1:
				sum += ws[1]
				res.append(ws[1])
				ws.pop(1)
			else:
				return []
		else:
			sum += ws[0]
			res.append(ws[0])
			ws.pop(0)
	return res
main()


k = int(input())
while k > 0:
	l = list(map(int, input().split()))
	n = l[0]
	x = l[1]
	suma_elemente = 0
	adev = 1
	li = list(map(int, input().split()))
	for i in range(0, n):
		suma_elemente = suma_elemente + li[i]
		if suma_elemente == x and i < n - 1:
			j = li[i]
			li[i] = li[i + 1]
			li[i + 1] = j
			i = n + 1
	if suma_elemente == x and i == n - 1:
		adev = 0
	if adev == 0:
		print('NO')
	else:
		print('YES')
		print(*li)
	k = k - 1


import math
for i in range(int(input())):
	a = [int(j) for j in input().split()]
	n = a[0]
	x = a[1]
	a = [int(j) for j in input().split()]
	sum = [a[0]] + [0 for j in range(n - 1)]
	for j in range(1, n):
		sum[j] = sum[j - 1] + a[j]
	if sum[n - 1] == x:
		print('NO')
	else:
		for j in range(n - 1):
			if sum[j] == x:
				(a[j], a[j + 1]) = (a[j + 1], a[j])
		print('YES')
		print(*a)


def prefix_sum(array):
	sum = 0
	retval = []
	for num in array:
		sum += num
		retval.append(sum)
	return retval
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	w.sort(key=int)
	if sum(w) == x:
		print('NO')
		continue
	p = prefix_sum(w)
	if x in p:
		i = p.index(x)
		(w[i], w[i + 1]) = (w[i + 1], w[i])
	print('YES')
	print(' '.join(map(str, w)))


def explodes(weights, avoid_weight):
	if len(weights) == 1 and weights[0] == avoid_weight:
		return 'NO'
	total = 0
	for i in range(len(weights) - 1):
		if total + weights[i] == avoid_weight:
			(weights[i], weights[i + 1]) = (weights[i + 1], weights[i])
		total += weights[i]
	if total + weights[-1] == avoid_weight:
		return 'NO'
	print('YES')
	return ' '.join([str(i) for i in weights])
for _ in range(int(input())):
	(gold_pieces, avoid_weight) = map(int, input().split())
	weights = list(map(int, input().split()))
	print(explodes(weights, avoid_weight))


for _ in range(int(input())):
	(n, x) = list(map(int, input().split(' ')))
	w = list(map(int, input().split(' ')))
	if sum(w) == x:
		print('NO')
	else:
		print('YES')
		s = w[0]
		for i in range(1, n):
			if s == x:
				(w[i - 1], w[i]) = (w[i], w[i - 1])
				break
			s += w[i]
		print(*w)


import random
t = int(input())
for tt in range(t):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	sm = sum(w)
	if sm < x:
		print('YES')
		print(' '.join(map(str, w)))
		continue
	if sm == x:
		print('NO')
		continue
	if sm > x:
		if all([w[i] == w[0] for i in range(n)]):
			if x % w[0] == 0:
				print('NO')
				continue
			else:
				print('YES')
				print(' '.join(map(str, w)))
				continue
		else:
			print('YES')
			sm = x
			while sm == x:
				sm = 0
				random.shuffle(w)
				for e in w:
					sm += e
					if sm == x:
						break
					elif sm > x:
						print(' '.join(map(str, w)))
						break
pass


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(n, w) = invr()
	a = inara()
	a.sort()
	tot = 0
	for i in range(n):
		tot += a[i]
		if tot == w:
			(a[i], a[n - 1]) = (a[n - 1], a[i])
			break
	tot = 0
	flag = True
	for i in range(n):
		tot += a[i]
		if tot == w:
			flag = False
	if flag:
		print('YES')
		print(*a)
	else:
		print('NO')


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().split()]
	if set(a) == {x} or sum(a) == x:
		print('no')
	else:
		a = sorted(a)
		val = 0
		for i in range(n):
			val += a[i]
			if val == x:
				(a[i], a[-1]) = (a[-1], a[i])
				break
		print('yes')
		print(*a)


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	t1 = 0
	flag = 0
	for i in range(n):
		t1 += a[i]
		if t1 == x:
			if i == n - 1:
				flag = 1
				break
			else:
				t1 -= a[i]
				t2 = a[i + 1]
				t3 = a[i]
				a[i] = t2
				a[i + 1] = t3
				t1 += a[i]
	if flag == 0:
		print('YES')
		for i in a:
			print(i, end=' ')
		print()
	else:
		print('NO')


for ii in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	sum = 0
	for i in range(n):
		sum += l[i]
		if sum != x:
			None
		elif i < n - 1:
			sum = sum + l[i + 1]
			(l[i], l[i + 1]) = (l[i + 1], l[i])
			break
	if sum == x:
		print('NO')
	else:
		print('YES')
		print(*l)


import sys

def input():
	return sys.stdin.readline()
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) == x:
		print('NO')
	elif max(a) > x:
		for i in range(n):
			if a[i] > x:
				(a[i], a[0]) = (a[0], a[i])
				break
		print('YES')
		print(*a)
	else:
		tot = 0
		for i in range(n):
			tot += a[i]
			if tot == x and i + 1 < n:
				(a[i], a[i + 1]) = (a[i + 1], a[i])
				break
		print('YES')
		print(*a)


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
for t in [wtf[i:i + 2] for i in range(1, len(wtf), 2)]:
	(n, x) = map(int, t[0].split())
	W = list(map(int, t[1].split()))
	tw = 0
	for i in range(n):
		tw += W[i]
		if tw == x and i + 1 < n:
			tw -= W[i]
			(W[i], W[i + 1]) = (W[i + 1], W[i])
			tw += W[i]
	print('NO' if tw == x else f"YES\n{' '.join(map(str, W))}")


def solve():
	(n, k) = (int(x) for x in input().split())
	arr = [int(x) for x in input().split()]
	if sum(arr) == k:
		print('NO')
		return
	arr.sort()
	s = 0
	found = -1
	for (ind, v) in enumerate(arr):
		s += v
		if s == k:
			found = ind
			break
	if found != -1:
		(arr[ind], arr[ind + 1]) = (arr[ind + 1], arr[ind])
	print('YES')
	print(' '.join(map(lambda x: str(x), arr)))
kk = int(input())
for _ in range(kk):
	solve()


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, x) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	i = 0
	s = 0
	ans = ''
	a = 0
	while i < n:
		s += arr[i]
		if s == x:
			if i + 1 < n:
				ans += str(arr[i + 1]) + ' ' + str(arr[i]) + ' '
				s += arr[i + 1]
				i += 2
			else:
				a = 1
		else:
			ans += str(arr[i]) + ' '
			i += 1
	if a == 1:
		print('NO')
	else:
		print('YES')
		print(ans)


for i in range(int(input())):
	(n, x) = [int(x) for x in input().split()]
	l = list(map(int, input().split()))
	if sum(l) != x:
		print('YES')
		g = []
		s = 0
		m = 0
		flag = 0
		for i in range(0, n):
			if s + l[i] != x:
				g.append(l[i])
				s = s + l[i]
				if flag == 1:
					g.append(m)
					flag = 0
					m = 0
			elif flag == 0:
				flag = 1
				m = l[i]
		if m != 0:
			g.append(m)
		print(*g)
	else:
		print('NO')


from sys import stdin
from collections import defaultdict
N = int(stdin.readline())
for t in range(N):
	(n, x) = list(map(int, stdin.readline().split()))
	S = sorted(list(map(int, stdin.readline().split())))
	if sum(S) == x:
		print('NO')
	else:
		cums = [0]
		for s in S:
			cums.append(cums[-1] + s)
		cums = cums[1:]
		if x in cums:
			where = cums.index(x)
			S = S[:where] + S[where:where + 2][::-1] + S[where + 2:]
		print('YES')
		print(' '.join(map(str, S)))


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def solve():
	for _ in range(get_int()):
		(n, x) = get_ints()
		w = get_list()
		summ = 0
		f = 0
		for i in range(n):
			summ += w[i]
			if summ == x:
				if i + 1 < n:
					y = w[i]
					(w[i], w[i + 1]) = (w[i + 1], w[i])
					summ -= y
					summ += w[i]
				else:
					f = 1
					break
		if f == 1 or summ == x:
			get_print('NO')
		else:
			get_print('YES')
			get_print(' '.join(map(str, w)))
solve()


Test = int(input())
for T in range(Test):
	(N, K) = map(int, input().split())
	Dta = list(map(int, input().split()))
	if sum(Dta) == K:
		print('NO')
	else:
		for i in range(N):
			if Dta[i] == K:
				(Dta[i], Dta[i + 1]) = (Dta[i + 1], Dta[i])
			K -= Dta[i]
		print('YES')
		print(*Dta)


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	s = sum(w)
	if s == x:
		print('NO')
	else:
		print('YES')
		ans = []
		i = 0
		while i < n:
			if w[i] == x:
				ans.append(w[i + 1])
				ans.append(w[i])
				x -= w[i]
				x -= w[i + 1]
				i += 2
			else:
				ans.append(w[i])
				x -= w[i]
				i += 1
		print(*ans)


t = int(input())

def solver(arr, x):
	rs = 0
	loc = 101
	for i in range(len(arr)):
		rs = rs + arr[i]
		if rs == x:
			loc = i
	if loc < len(arr) - 1:
		temp = arr[loc]
		arr[loc] = arr[loc + 1]
		arr[loc + 1] = temp
	if loc == len(arr) - 1:
		return ('No', [])
	else:
		return ('Yes', arr)
res = []
for i in range(t):
	[n, x] = [int(item) for item in input().split()]
	arr = [int(item) for item in input().split()]
	res.append(solver(arr, x))
for arr in res:
	if arr[0] == 'No':
		print('NO')
	else:
		arr2 = [str(item) for item in arr[1]]
		string = ' '.join(arr2)
		print('YES')
		print(string)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	w = sorted(list(map(int, input().split())))
	sm = 0
	for i in range(n - 1):
		if sm + w[i] == x:
			(w[i], w[i + 1]) = (w[i + 1], w[i])
		sm += w[i]
	if sm + w[-1] == x:
		print('NO')
	else:
		print('YES')
		print(' '.join(map(str, w)))


t = int(input())
for _ in range(t):
	(n, x) = [int(x) for x in input().split()]
	ws = [int(x) for x in input().split()]
	s = 0
	bad = False
	for i in range(n):
		s += ws[i]
		if s == x:
			if i < n - 1:
				(ws[i], ws[i + 1]) = (ws[i + 1], ws[i])
			else:
				bad = True
			break
	if bad:
		print('NO')
	else:
		print('YES')
		print(' '.join(map(str, ws)))


n = int(input())
for i in range(n):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort(reverse=True)
	if A[0] > k:
		print('YES')
		print(' '.join((str(i) for i in A)))
	elif sum(A) == k:
		print('NO')
	else:
		print('YES')
		S = [A[0]]
		Flag = False
		if A[0] == k:
			(A[0], A[1]) = (A[1], A[0])
			Flag = True
		a = len(A) - 1
		i = 1
		while i <= a and Flag == False:
			S.append(S[i - 1] + A[i])
			if S[i] == k:
				(A[i], A[i + 1]) = (A[i + 1], A[i])
				Flag = True
				break
			i += 1
		print(' '.join((str(i) for i in A)))


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if sum(a) == x:
		print('NO')
		continue
	a.sort(reverse=True)
	res = 0
	for i in range(n):
		res += a[i]
		if res == x:
			t = a[i]
			a[i] = a[i + 1]
			a[i + 1] = t
	a = list(map(str, a))
	print('YES')
	print(' '.join(a))


def go():
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = 0
	for i in range(n):
		s += arr[i]
		if s == x:
			if i == n - 1:
				print('NO')
				return None
			else:
				print('YES')
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
				print(' '.join(map(str, arr)))
				return None
	print('YES')
	print(' '.join(map(str, arr)))
	return None
for i in range(int(input())):
	go()


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	flag = 0
	ans = []
	s = 0
	ind = -1
	if sum(A) == k:
		print('NO')
	else:
		A.sort()
		for i in range(n):
			if s + A[i] == k:
				ind = i
			else:
				ans.append(A[i])
				s += A[i]
		if ind != -1:
			ans.append(A[ind])
		print('YES')
		print(*ans)


t = int(input())
while t:
	(n, x) = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	if sum(w) == x:
		print('NO')
	elif sum(w) < x:
		print('YES')
		print(*w)
	else:
		w.sort(reverse=True)
		pos = -1
		s = 0
		ans = []
		for i in range(n):
			if s + w[i] == x:
				if pos != -1:
					ans.append(w[pos])
					s += w[pos]
				pos = i
				continue
			else:
				s += w[i]
				ans.append(w[i])
		if pos != -1:
			ans.append(w[pos])
		print('YES')
		print(*ans)
	t -= 1


cases = int(input())

def solve():
	(n, x) = list(map(int, input().strip().split()))[:2]
	arr = list(map(int, input().strip().split()))[:n]
	summ = sum(arr)
	if summ == x:
		print('NO')
		return
	hashs = {}
	newArr = []
	total_weight = 0
	while len(hashs) < len(arr):
		for i in range(len(arr)):
			if i in hashs:
				continue
			elif arr[i] + total_weight != x:
				total_weight += arr[i]
				hashs[i] = True
				newArr.append(arr[i])
	print('YES')
	print(' '.join(list(map(str, newArr))))
for case in range(cases):
	solve()


def function(array, x):
	array.sort()
	solt = []
	new_array = []
	sums = 0
	flag = False
	flag2 = False
	count = 0
	while sums != x and count < len(array):
		sums += array[count]
		if sums > x:
			flag = True
		if sums == x:
			flag2 = True
			sums -= array[count]
			new_array.append(array[count])
		else:
			solt.append(array[count])
		count += 1
	if not (flag or not flag2):
		return 'NO'
	print('YES')
	solt += new_array
	return ' '.join(map(str, solt))
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	array = list(map(int, input().split()))
	print(function(array, x))


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	s = 0
	nl = []
	b = 0
	for i in range(n):
		s += l[i]
		if s == x:
			if n > i + 1:
				temp = l[i]
				l[i] = l[i + 1]
				l[i + 1] = temp
			else:
				b = 1
			break
	if b == 0:
		print('YES')
		for j in range(n):
			print(l[j], end=' ')
	else:
		print('NO')
	print()


def fun(ls, ks):
	(n, x) = ks
	st = sorted(ls)
	sm = sum(ls)
	if st[-1] > x:
		print('YES')
		print(*st[::-1])
		return
	if sm < x:
		print('YES')
		print(*st)
		return
	if sm == x:
		print('NO')
		return
	ans = []
	prv = None
	leave = None
	for i in st:
		if prv == None:
			prv = i
		else:
			prv += i
		if prv == x:
			leave = i
		else:
			ans.append(i)
	if leave == None:
		print('YES')
		print(*st)
	else:
		ans.append(leave)
		print('YES')
		print(*ans)
T = int(input())
for i in range(T):
	ks = list(map(int, input().split()))
	ls = list(map(int, input().split()))
	fun(ls, ks)


for test in range(int(input())):
	(n, x) = map(int, input().split())
	lst = sorted(map(int, input().split()))
	ans = []
	if sum(lst) == x:
		print('NO')
		continue
	while x > 0 and len(lst) > 1:
		for i in range(len(lst)):
			if lst[i] != x:
				x -= lst[i]
				ans.append(lst.pop(i))
				break
	ans += lst
	print('YES')
	print(*ans)


n = int(input(''))
for i in range(n):
	(t, x) = map(int, input('').split())
	a = list(map(int, input('').split()))
	Sum = 0
	for i in range(len(a) - 1):
		if a[i] + Sum == x:
			for j in range(i + 1, len(a)):
				if a[j] + Sum != x:
					temp = a[i]
					a[i] = a[j]
					a[j] = temp
					break
		Sum += a[i]
	if sum(a) == x:
		print('NO')
	else:
		print('YES')
		print(' '.join(map(str, a)))


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import threading
import sys
import time

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	(n, x) = get_tuple()
	ls = get_list()
	ls.sort()
	pref_sum = 0
	ans = []
	(rem, rem_ind) = (-1, -1)
	for (i, val) in enumerate(ls):
		pref_sum += val
		if pref_sum == x:
			rem = val
			rem_ind = i
		else:
			ans.append(val)
	if rem_ind == -1:
		print('YES')
		print(*ans)
	elif rem_ind != n - 1:
		ans.append(rem)
		print('YES')
		print(*ans)
	else:
		print('NO')
testcases = True
if testcases:
	t = get_int()
	for _ in range(t):
		solve()
else:
	solve()


def solveq1():
	(n, x) = [int(x) for x in input().split(' ')]
	gold = sorted([int(x) for x in input().split(' ')])
	total = 0
	for (i, g) in enumerate(gold):
		total += g
		if total == x:
			if i == len(gold) - 1:
				print('NO')
			else:
				print('YES')
				ans = gold[:i] + [gold[i + 1]] + [gold[i]] + gold[i + 2:]
				print(' '.join([str(x) for x in ans]))
			return
	print('YES')
	print(' '.join([str(x) for x in gold]))
for tc in range(int(input())):
	solveq1()


for i in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	tot = sum(arr)
	if x == tot:
		print('NO')
		continue
	sum1 = 0
	for j in range(n - 1):
		sum1 += arr[j]
		if sum1 == x:
			(arr[j], arr[j + 1]) = (arr[j + 1], arr[j])
	print('YES')
	print(*arr)


def prog_name():
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	su = 0
	flag = False
	for x in range(len(l)):
		su += l[x]
		if su == k:
			if x == n - 1:
				flag = True
			else:
				temp = l[x]
				l[x] = l[x + 1]
				l[x + 1] = temp
	if flag == True:
		print('NO')
	else:
		print('YES')
		print(*l)
t = int(input())
for unique in range(t):
	prog_name()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	w = [int(i) for i in input().split()]
	w.sort()
	if sum(w) == x:
		print('NO')
	else:
		print('YES')
		total_sum = 0
		order = []
		in_the_end = 0
		for w_i in w:
			if total_sum + w_i == x:
				in_the_end = w_i
			else:
				total_sum += w_i
				order.append(w_i)
		if in_the_end:
			order.append(in_the_end)
		print(*order)


t = int(input())
for j in range(t):
	(n, x) = map(int, input().split(' '))
	w = list(map(int, input().split(' ')))
	w.sort()
	s = 0
	res = []
	i = 0
	while i < n:
		if s + w[i] != x:
			s += w[i]
			res.append(w[i])
			i += 1
		elif i + 1 < n:
			res.append(w[i + 1])
			res.append(w[i])
			i += 2
		else:
			break
	if i < n:
		print('NO')
	else:
		print('YES')
		print(' '.join((str(a) for a in res)))


t = int(input())
arr = []
ans_arr = []
for i in range(t):
	first_string = list(map(int, input().split()))
	second_string = list(map(int, input().split()))
	both_strings = first_string + second_string
	arr.append(both_strings)
for i in arr:
	forbidden = i[1]
	weights = i[2:]
	weights_sum = 0
	answer = 'YES'
	if sum(weights) == forbidden:
		answer = 'NO'
		ans_arr.append(answer)
	else:
		for j in range(len(weights) - 1):
			weights_sum += weights[j]
			if weights_sum == forbidden:
				n = weights[j]
				weights[j] = weights[j + 1]
				weights[j + 1] = n
		ans_arr.append(answer)
		ans_arr.append(weights)
for i in ans_arr:
	if type(i) != list:
		i = i
	else:
		i = list(map(str, i))
		i = ' '.join(i)
	print(i)


import sys

def read_ints():
	return [int(i) for i in sys.stdin.readline().strip().split()]

def read_int():
	return int(sys.stdin.readline().strip())
t = read_int()
for i in range(t):
	(n, x) = read_ints()
	ws = read_ints()
	ws.sort()
	if sum(ws) == x:
		print('NO')
		continue
	print('YES')
	total = 0
	j = 0
	while j < n:
		if total + ws[j] == x:
			print(ws[j + 1], ws[j], end=' ')
			total += ws[j] + ws[j + 1]
			j += 2
		else:
			print(ws[j], end=' ')
			total += ws[j]
			j += 1
	print()


t_case = int(input())
for i in range(t_case):
	lst1 = input().split()
	(n, x) = (int(lst1[0]), int(lst1[1]))
	lst2 = [int(num) for num in input().split()]
	lst2.sort(reverse=True)
	if lst2[0] > x:
		print('YES')
		print(' '.join((str(num) for num in lst2)))
		continue
	elif sum(lst2) < x:
		print('YES')
		print(' '.join((str(num) for num in lst2)))
		continue
	else:
		tot = 0
		lst4 = []
		lst5 = []
		for i in lst2:
			if tot + i != x:
				tot += i
				lst4.append(i)
			else:
				lst5.append(i)
		if tot > x:
			print('YES')
			print(' '.join((str(i) for i in lst4)), ' '.join((str(i) for i in lst5)))
		elif tot < x:
			lst6 = []
			for i in lst5:
				if tot + i != x:
					tot += i
					lst4.append(i)
				else:
					lst6.append(i)
			if tot > x:
				print('YES')
				print(' '.join((str(i) for i in lst4)), ' '.join((str(i) for i in lst6)))
			else:
				print('NO')
		else:
			print('NO')


t = int(input())
m = []
for i in range(t):
	(n, x) = input().split()
	n = int(n)
	x = int(x)
	p = list(map(int, input().split()))
	soma = sum(p)
	if x == soma:
		print('NO')
	else:
		print('YES')
		for j in range(len(p)):
			if x == p[j]:
				temp = p[j]
				p[j] = p[j + 1]
				p[j + 1] = temp
			print(p[j], end=' ')
			x -= p[j]
		print()


from __future__ import division, print_function
import math
import os
import sys
from fractions import *
from sys import *
from decimal import *
from io import BytesIO, IOBase
from itertools import *
from collections import *
M = 10 ** 9 + 7
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def binpowmodulus(a, b, m):
	a %= m
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b >>= 1
	return res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def prime(x):
	if x == 1:
		return False
	else:
		for i in range(2, int(math.sqrt(x)) + 1):
			if x % i == 0:
				return False
		else:
			return True

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynum(x, l, r, a):
	if x >= l and x <= r:
		a.append(x)
	if x > r:
		a.append(x)
		return a
	if x < 10000000000.0:
		luckynum(x * 10 + 4, l, r, a)
		luckynum(x * 10 + 7, l, r, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a

def interact(type, x):
	if type == 'r':
		inp = input()
		return inp.strip()
	else:
		print(x, flush=True)

def findTrailingZeros(n):
	count = 0
	while n >= 5:
		n //= 5
		count += n
	return count

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
res = set()

def solven(p, l, a, b, n):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solven(p * 10 + a, l + 1, a, b, n)
	solven(p * 10 + b, l + 1, a, b, n)

def subsetsUtil(A, subset, index, d):
	print(*subset)
	s = sum(subset)
	d.append(s)
	for i in range(index, len(A)):
		subset.append(A[i])
		subsetsUtil(A, subset, i + 1, d)
		subset.pop(-1)
	return d

def subsetSums(arr, l, r, d, sum=0):
	if l > r:
		d.append(sum)
		return
	subsetSums(arr, l + 1, r, d, sum + arr[l])
	subsetSums(arr, l + 1, r, d, sum)
	return d

def print_factors(x):
	factors = []
	for i in range(1, x + 1):
		if x % i == 0:
			factors.append(i)
	return factors

def calc(X, d, ans, D):
	if len(X) == 0:
		return
	i = X.index(max(X))
	ans[D[max(X)]] = d
	Y = X[:i]
	Z = X[i + 1:]
	calc(Y, d + 1, ans, D)
	calc(Z, d + 1, ans, D)

def factorization(n, l):
	c = n
	if prime(n) == True:
		l.append(n)
		return l
	for i in range(2, c):
		if n == 1:
			break
		while n % i == 0:
			l.append(i)
			n = n // i
	return l

def good(b):
	l = []
	i = 0
	while len(b) != 0:
		if b[i] < b[len(b) - 1 - i]:
			l.append(b[i])
			b.remove(b[i])
		else:
			l.append(b[len(b) - 1 - i])
			b.remove(b[len(b) - 1 - i])
	if l == sorted(l):
		return True
	return False

def generate(st, s):
	if len(s) == 0:
		return
	if s not in st:
		st.add(s)
		for i in range(len(s)):
			t = list(s).copy()
			t.remove(s[i])
			t = ''.join(t)
			generate(st, t)
	return

def largestincreasingsubsequence(A):
	l = [1] * len(A)
	sub = []
	for i in range(1, len(l)):
		for k in range(i):
			if A[k] < A[i]:
				sub.append(l[k])
		l[i] = 1 + max(sub, default=0)
	return max(l, default=0)

def findOR(nums, N):
	prefix_sum = 0
	result = 0
	for i in range(N):
		result |= nums[i]
		prefix_sum += nums[i]
		result |= prefix_sum
	return result

def OR(a, n):
	ans = a[0]
	for i in range(1, n):
		ans |= a[i]
	return ans

def main():
	for _ in range(inpu()):
		(n, x) = sep()
		arr = lis()
		if len(set(arr)) == 1 and arr[0] == x or sum(arr) == x:
			print('NO')
			continue
		s = 0
		ans = []
		q = []
		for i in range(n):
			s += arr[i]
			if s == x:
				s -= arr[i]
				q.append(arr[i])
			else:
				ans.append(arr[i])
		if len(q) == 1 and q[0] == arr[n - 1]:
			ans = q + ans
		else:
			ans += q
		print('YES')
		print(*ans)
main()


T = int(input())
t = 1
while t <= T:
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) == x:
		print('NO')
		t += 1
		continue
	arr = sorted(arr)
	tot = 0
	for i in range(n - 1):
		tot += arr[i]
		if tot == x:
			(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
	print('YES')
	print(' '.join(map(str, arr)))
	t += 1


for testis in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	f = 1
	if s == x:
		print('NO')
	else:
		s = 0
		for i in range(n):
			s += l[i]
			if s == x:
				(l[i], l[i + 1]) = (l[i + 1], l[i])
				break
		print('YES')
		print(*l)


for t in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	k = sum(l)
	if k == x:
		print('NO')
	else:
		print('YES')
		c = 0
		k = []
		for i in range(n):
			c += l[i]
			if c == x:
				(l[i], l[i + 1]) = (l[i + 1], l[i])
				c -= l[i + 1]
				c += l[i]
				k.append(l[i])
			else:
				k.append(l[i])
		print(*k)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	w.sort()
	flag = 0
	s = 0
	for i in range(len(w)):
		s = s + w[i]
		if s == x:
			if s - w[i] + w[-1] <= x:
				print('NO')
				flag = 1
				break
			else:
				print('YES')
				print(*w[:i], w[-1], *w[i:-1])
				flag = 1
				break
	if flag == 0:
		print('YES')
		print(*w)


from collections import deque
t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	dq = deque(w)
	ans = []
	acc = 0
	while dq:
		if acc + dq[0] != x:
			acc += dq[0]
			ans.append(dq.popleft())
		elif acc + dq[-1] != x:
			acc += dq[-1]
			ans.append(dq.pop())
		else:
			print('NO')
			break
	if len(ans) == n:
		print('YES')
		print(' '.join(map(str, ans)))


cases = int(input())

def yes(w):
	print('YES')
	print(' '.join([str(t) for t in w]))
for i in range(cases):
	a = input().split()
	b = input().split()
	(_, x) = (int(a[0]), int(a[1]))
	w = [int(aa) for aa in b]
	if sum(w) == x:
		print('NO')
		continue
	if sum(w) < x:
		yes(w)
		continue
	w = sorted(w)
	w = [ww for ww in reversed(w)]
	total = 0
	for (i, num) in enumerate(w):
		total += num
		if total == x:
			temp = w[i]
			w[i] = w[i + 1]
			w[i + 1] = temp
			yes(w)
			break
		if total > x:
			yes(w)
			flag = False
			break


t = int(input())
for case in range(t):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	s = sum(w)
	if s == x:
		print('NO')
		continue
	cs = 0
	for i in range(n):
		cs += w[i]
		if cs == x:
			(w[i], w[i + 1]) = (w[i + 1], w[i])
			break
	print('YES')
	print(' '.join(map(str, w)))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	if sum(w) == x:
		print('NO')
		continue
	print('YES')
	w.sort(reverse=True)
	total = 0
	while len(w) > 0:
		total += w[0]
		if total == x:
			total += w[1]
			print(w.pop(1), end=' ')
		print(w.pop(0), end=' ')
	print()


for i in range(int(input())):
	(n, x) = [int(a) for a in input().split()]
	sum_lst = 0
	stored_elem = -1
	res = []
	flag = True
	for (j, elem) in enumerate(input().split()):
		elem = int(elem)
		if stored_elem != -1:
			res.append(elem)
			sum_lst += elem
			res.append(stored_elem)
			stored_elem = -1
		else:
			sum_lst += elem
			if sum_lst == x:
				if j == n - 1:
					print('NO')
					flag = False
				else:
					stored_elem = elem
			else:
				res.append(elem)
	if flag:
		print('YES')
		print(' '.join([str(elem) for elem in res]))


def solve(arr, x):
	res = []
	arr.sort(reverse=True)
	s = 0
	i = 0
	while i < len(arr):
		s += arr[i]
		if s != x:
			res.append(arr[i])
			i += 1
		else:
			j = i
			while i < len(arr) and arr[i] == arr[j]:
				i += 1
			if i < len(arr):
				res.append(arr[i])
				for t in range(j, i):
					res.append(arr[t])
			i += 1
	if len(res) == len(arr):
		return (True, res)
	else:
		return (False, -1)
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	(isPos, ans) = solve(arr, x)
	if isPos:
		print('YES')
		print(*ans)
	else:
		print('NO')


for tc in range(int(input())):
	(n, k) = map(int, input().split())
	w = list(map(int, input().split()))
	if sum(w) == k:
		print('NO')
		continue
	s = 0
	for i in range(n):
		s += w[i]
		if s == k:
			(w[i], w[i + 1]) = (w[i + 1], w[i])
			break
	print('YES')
	print(' '.join((str(i) for i in w)))


def inputi():
	return int(input())

def inputli():
	return list(map(int, input().split(' ')))

def inputls():
	return list(map(str, input().split(' ')))

def print_list(lista):
	s = ''
	for i in lista[:-1]:
		s += str(i) + ' '
	s += str(lista[-1])
	return s

def solve():
	[n, k] = inputli()
	numbers = inputli()
	band = 'NO'
	ans = []
	maxi = max(numbers)
	suma = sum(numbers)
	if k == suma:
		return (band, ans)
	id = numbers.index(maxi)
	if k < maxi:
		ans = [maxi] + [e for (i, e) in enumerate(numbers) if i != id]
		return ('YES', ans)
	numbers = sorted(numbers)
	suma = 0
	for (idx, a) in enumerate(numbers):
		suma += a
		if suma == k and idx != n - 1:
			ans += numbers[idx + 1:] + [a]
			return ('YES', ans)
		ans.append(a)
	return ('YES', ans)
t = inputi()
for i in range(t):
	(band, ans) = solve()
	if band == 'NO':
		print(band)
	else:
		print(band)
		print(print_list(ans), end='')
		print('') if i != t - 1 else None


def main():
	for _ in range(int(input())):
		(n, x) = map(int, input().split())
		arr = list(map(int, input().split()))
		if len(set(arr)) == 1 and arr[0] == x or sum(arr) == x:
			print('NO')
			continue
		s = 0
		ans = []
		q = []
		for i in range(n):
			s += arr[i]
			if s == x:
				s -= arr[i]
				q.append(arr[i])
			else:
				ans.append(arr[i])
		if len(q) == 1 and q[0] == arr[n - 1]:
			ans = q + ans
		else:
			ans += q
		print('YES')
		print(*ans)
main()


T = int(input())
for _ in range(T):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) == x:
		print('NO')
	else:
		ans = []
		summ = 0
		i = 0
		while i < n:
			summ += a[i]
			if summ == x:
				ans.append(a[i + 1])
				ans.append(a[i])
				i += 1
			else:
				ans.append(a[i])
			i += 1
		print('YES')
		print(*ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	golds = sorted(list(map(int, input().split())))
	if sum(golds) == x:
		print('NO')
		continue
	lst = []
	s = 0
	while n != 0:
		if s + golds[0] != x:
			lst.append(golds[0])
			s += golds[0]
			golds.pop(0)
		else:
			lst.append(golds[-1])
			s += golds[-1]
			golds.pop(-1)
		n -= 1
	print('YES')
	print(' '.join(map(str, lst)))


import sys
import heapq
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(n, x) = inlt()
	numbers = inlt()
	if sum(numbers) == x:
		print('NO')
	else:
		total = 0
		result = ''
		i = 0
		while i < len(numbers):
			if numbers[i] + total == x:
				result += ' ' + str(numbers[i + 1]) + ' ' + str(numbers[i])
				total += numbers[i] + numbers[i + 1]
				i += 2
			else:
				result += ' ' + str(numbers[i])
				total += numbers[i]
				i += 1
		result = result[1:]
		print('YES')
		print(result)


T = int(input())
for t in range(T):
	nx = list(map(int, input().split()))
	n = nx[0]
	x = nx[1]
	w = list(map(int, input().split()))
	s = sum(w)
	if s == x:
		print('NO')
		continue
	if s < x:
		print('YES')
		for i in range(n):
			print(w[i], end=' ')
		print()
		continue
	w.sort()
	if x < w[n - 1]:
		(w[0], w[n - 1]) = (w[n - 1], w[0])
		print('YES')
		for i in range(n):
			print(w[i], end=' ')
		print()
		continue
	c = 0
	for i in range(n):
		c += w[i]
		if c == x:
			if i == n - 1:
				(w[i], w[i - 1]) = (w[i - 1], w[i])
			else:
				(w[i], w[i + 1]) = (w[i + 1], w[i])
	print('YES')
	for i in range(n):
		print(w[i], end=' ')
	print()


T = int(input())
for i in range(T):
	(N, x) = map(int, input().split(' '))
	s = input() + ' '
	y = ''
	n = 0
	total = 0
	A = []
	c = False
	p = 0
	for j in range(N):
		term = ''
		y = s[n]
		while y != ' ':
			term += y
			n += 1
			y = s[n]
		total += int(term)
		A.append(int(term))
		n += 1
		if total == x:
			c = True
			p = j
	if c == False:
		print('YES')
		for k in range(N):
			print(A[k], end=' ')
		print()
		continue
	if p == N - 1:
		print('NO')
		continue
	else:
		print('YES')
		(A[p], A[p + 1]) = (A[p + 1], A[p])
	for k in range(N):
		print(A[k], end=' ')
	print()


def uvecajj(j, n):
	if j == n - 1:
		return 0
	else:
		return j + 1

def moze(lista, n, x):
	sua = 0
	su = 0
	while su < n:
		sua += lista[su]
		su += 1
	if sua == x:
		print('NO')
	else:
		j = 0
		broj = 0
		lista2 = ''
		while len(lista) != 0:
			if broj + lista[j] == x:
				j = uvecajj(j, n)
			else:
				broj = broj + lista[j]
				lista2 += str(lista[j])
				lista2 += ' '
				del lista[j]
				n -= 1
				if n == j:
					j = 0
		print('YES')
		print(lista2)
t = int(input())
while t > 0:
	lis = input().split(' ')
	n = int(lis[0])
	x = int(lis[1])
	lista = [int(i) for i in input().split(' ')]
	moze(lista, n, x)
	t -= 1


def solve(n, x, arr):
	if sum(arr) == x:
		print('NO')
	else:
		arr = sorted(arr, reverse=True)
		s = sum(arr)
		i = 0
		curr = 0
		res = []
		while i < len(arr):
			if curr > x:
				i = len(arr)
				continue
			if curr + arr[i] == x:
				i += 1
				continue
			curr += arr[i]
			res.append(arr.pop(i))
		if curr > x:
			res += arr
			curr += sum(arr)
			arr = []
		if arr:
			if curr + sum(arr) == s and curr != x:
				res += arr
				curr += sum(arr)
				arr = []
		if curr == s:
			print('YES')
			print(' '.join(map(str, res)))
		else:
			print('NO')
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	solve(n, x, list(map(int, input().split())))


from sys import path_hooks, stdin, stdout
from collections import Counter, deque
import math
from copy import deepcopy
import random

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	ans = []
	for p in range(n + 1):
		if prime[p]:
			ans.append(p)
	return ans
coprime1 = {6: 100003, 5: 10007, 4: 1009, 3: 101, 2: 11, 1: 2, 7: 1000003, 8: 10000019, 9: 100000007}
coprime2 = {8: 10000169, 9: 100000049, 7: 1000033, 6: 100019, 5: 10009, 4: 1013, 3: 103, 2: 13, 1: 3}

def writ(ss):
	stdout.write(str(ss) + '\n')
mod = 10 ** 9 + 7
for test in range(int(int(stdin.readline()))):
	(n, x) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	ans = []
	if sum(arr) == x:
		print('NO')
	else:
		print('YES')
		while 0 == 0:
			random.shuffle(arr)
			i = arr
			su = 0
			for j in i:
				su += j
				if su == x:
					break
			if su != x:
				print(*i)
				break


import random
import math
from collections import defaultdict
import itertools
from sys import stdin, stdout

def main():
	z = ''
	for _ in range(int(stdin.readline())):
		(n, x) = list(map(int, stdin.readline().split()))
		w = list(map(int, stdin.readline().split()))
		w.sort(reverse=True)
		a = list(itertools.accumulate(w))
		s = ''
		if x not in a:
			print('YES')
			for j in range(n):
				s += str(w[j]) + ' '
			print(s)
		else:
			for k in range(n):
				if a[k] == x:
					l = k + 1
					while l < n:
						if w[k] != w[l]:
							(w[k], w[l]) = (w[l], w[k])
						l += 1
			a = list(itertools.accumulate(w))
			s = ''
			if x not in a:
				print('YES')
				for j in range(n):
					s += str(w[j]) + ' '
				print(s)
			else:
				print('NO')
main()


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	w = []
	w = input().split()
	su = 0
	p = 0
	s = ''
	for j in range(n):
		w[j] = int(w[j])
		su += w[j]
	if (su == x or su < x) and p == 0:
		if su == x:
			print('NO')
		if su < x:
			print('YES')
			for k in range(n):
				s = s + str(w[k]) + ' '
			print(s)
	else:
		print('YES')
		uu = x
		for k in range(n):
			uu -= w[k]
			if uu == 0:
				(w[k + 1], w[k]) = (w[k], w[k + 1])
				break
			if uu < 0:
				break
		for k in range(n):
			s = s + str(w[k]) + ' '
		print(s)


tkk = int(input())
for z in range(tkk):
	(numo, kulo) = map(int, input().split())
	lito = list(map(int, input().split()))
	if numo == 1:
		if lito[0] == kulo:
			print('NO')
		else:
			print('YES')
			print(lito[0])
	elif sum(lito) < kulo:
		print('YES')
		print(*lito)
	else:
		lito.sort(reverse=True)
		if lito[0] > kulo:
			print('YES')
			print(*lito)
		else:
			ss = 0
			yy = lito[0]
			f = 'NO'
			i = 0
			while i < numo:
				ss += lito[i]
				if ss == kulo:
					lito = lito[numo - 1:] + lito[:numo - 1]
					if lito[0] == yy:
						break
					ss = 0
					i = 0
					continue
				elif ss > kulo:
					f = 'YES'
					break
				else:
					pass
				i += 1
			if f == 'YES':
				print(f)
				print(*lito)
			else:
				print(f)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	s = 0
	i = 0
	j = n - 1
	p = []
	e = 0
	while i <= j:
		s = s + l[j]
		if s == x:
			j = j
			s = s - l[j]
			s = s + l[i]
			if s == x:
				print('NO')
				e = 1
				break
			else:
				p.append(l[i])
			i = i + 1
		else:
			p.append(l[j])
			j = j - 1
	if s == x and e == 0:
		print('NO')
	elif e == 0:
		print('YES')
		print(*p)


t = int(input())
while t:
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	soln = []
	sums = 0
	if sum(arr) == x:
		print('NO')
	else:
		for i in range(n):
			if sums + arr[i] == x:
				sums += arr[i + 1]
				soln.append(arr[i + 1])
				ele = arr[i + 1]
				arr[i + 1] = arr[i]
				arr[i] = ele
			else:
				sums += arr[i]
				soln.append(arr[i])
		else:
			val = ' '.join(map(str, arr))
			print('YES')
			print(val)
	t -= 1


t = int(input())
while t:
	t -= 1
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	sum = 0
	flag = True
	for i in range(n):
		sum += a[i]
		if sum == x:
			if i == n - 1:
				print('NO')
				flag = False
				break
			else:
				(a[i], a[i + 1]) = (a[i + 1], a[i])
	if flag == True:
		print('YES')
		for p in a:
			print(p, end=' ')
		print()


from itertools import accumulate
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	prefix = list(accumulate(w))
	if prefix[-1] == x:
		print('NO')
	else:
		print('YES')
		try:
			i = prefix.index(x)
			(w[i + 1], w[i]) = (w[i], w[i + 1])
		except:
			pass
		print(*w)


from math import gcd
from collections import defaultdict as dd
MOD = 10 ** 9 + 7

def R(type=int):
	line = input().rstrip()
	try:
		return type(line)
	except:
		pass
	return line
RL = lambda type=int: list(map(type, input().rstrip().split()))
RLL = lambda N, type=int: [RL(type) for _ in range(N)]
RLS = lambda N, type=int: [R(type) for _ in range(N)]

def solve():
	(N, X) = RL()
	W = sorted(RL())
	if sum(W) == X:
		print('NO')
		return
	total = 0
	i = 0
	res = []
	while i < N and total + W[i] < X:
		total += W[i]
		res += [W[i]]
		i += 1
	j = N - 1
	while j >= i:
		res += [W[j]]
		j -= 1
	print('YES')
	print(' '.join(map(str, res)))
T = R()
for t in range(T):
	solve()


import math
for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if x == sum(a):
		print('NO')
		continue
	s = 0
	a.sort()
	ans = []
	for i in range(n):
		s += a[i]
		if s == x:
			(a[i], a[i + 1]) = (a[i + 1], a[i])
	print('YES')
	print(*a)


for t in range(int(input())):
	(n, x) = map(int, input().split())
	n_lst = list(map(int, input().split()))
	add = 0
	if sum(n_lst) == x:
		print('NO')
	else:
		print('YES')
		for i in range(len(n_lst)):
			add += n_lst[i]
			if add == x:
				(n_lst[i], n_lst[i + 1]) = (n_lst[i + 1], n_lst[i])
				break
		print(' '.join(map(str, n_lst)))


out = []
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	c = list(map(int, input().split()))
	p = 0
	for i in range(n):
		p += c[i]
		if p == x and i < n - 1:
			p += c[i + 1] - c[i]
			(c[i], c[i + 1]) = (c[i + 1], c[i])
	if p == x:
		out.append('NO')
	else:
		out.append('YES')
		out.append(' '.join(map(str, c)))
print('\n'.join(out))


for _ in range(int(input())):
	(n, x) = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	if sum(w) == x:
		print('NO')
	else:
		print('YES')
		d = 0
		for i in range(n):
			d += w[i]
			if d == x:
				a = w[i:i + 2]
				a.reverse()
				w = w[:i] + a + w[i + 2:]
				break
		print(*w)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s == x:
		print('NO')
	else:
		f = 0
		(pre, i) = (0, 0)
		for i in range(n - 1):
			pre += arr[i]
			if pre == x:
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
		print('YES')
		print(*arr)


from sys import stdin, stdout
import math

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
for _ in range(ii()):
	(n, x) = mi()
	l1 = li()
	l1.sort()
	if sum(l1) == x:
		print('NO')
	else:
		print('YES')
		sum1 = 0
		for i in range(n):
			sum1 += l1[i]
			if sum1 == x:
				(l1[i], l1[-1]) = (l1[-1], l1[i])
				break
		print(*l1)


for j in range(int(input())):
	(n, x) = map(int, input().split())
	z = sorted(list(map(int, input().split())))
	c = 0
	if sum(z) == x:
		print('NO')
	else:
		for i in range(n):
			c += z[i]
			if c == x:
				(z[i], z[n - 1]) = (z[n - 1], z[i])
		print('YES')
		print(*z)


t = int(input())
for j in range(t):
	m = input().split()
	n = int(m[0])
	x = int(m[1])
	a = list(map(int, input().split()))
	w = sum(a)
	if w == x:
		print('NO')
	else:
		k = 0
		j = []
		print('YES')
		s = 0
		for i in a:
			s = s + i
			if s != x:
				print(i, end=' ')
			else:
				k = 1
				j.append(i)
				s = s - i
		if k != 0:
			print(*j)


def f(x, y):
	s = 0
	for (i, j) in zip(y, range(len(y))):
		s += i
		if s == x:
			return (True, j)
	return (False, 0)
for _ in range(int(input())):
	x = int(input().split(' ')[1])
	y = list(map(int, input().split(' ')))
	if sum(y) == x:
		print('NO')
	else:
		print('YES')
		z = sorted(y, key=lambda x: -x)
		while True:
			(st, j) = f(x, z)
			if st:
				t = z[j]
				z[j] = z[j + 1]
				z[j + 1] = t
			else:
				break
		print(' '.join(map(str, z)))


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().rstrip().split()))
	arr = list(map(int, input().rstrip().split()))
	arr.sort()
	sum_ = [arr[0]]
	for i in range(1, n):
		sum_.append(sum_[-1] + arr[i])
	if x not in sum_:
		print('YES')
		print(*arr)
	elif sum_[-1] == x:
		print('NO')
	else:
		index = sum_.index(x)
		(arr[index], arr[-1]) = (arr[-1], arr[index])
		print('YES')
		print(*arr)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	if sum(arr) == k:
		print('NO')
		continue
	curr = 0
	for i in range(n - 1):
		curr += arr[i]
		if curr == k:
			(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
			break
	print('YES')
	print(*arr)


def solve():
	for _ in range(int(input())):
		(n, x) = map(int, input().split())
		weights = list(map(int, input().split()))
		total = sum(weights)
		if total == x:
			print('NO')
		else:
			print('YES')
			acc = 0
			output = []
			while weights:
				w = weights.pop()
				if acc + w == x:
					w2 = weights.pop()
					acc += w2
					output.append(str(w2))
				acc += w
				output.append(str(w))
			print(' '.join(output))
solve()


from collections import deque
from sys import stdin

def read_int():
	return int(stdin.readline())

def read_ints():
	return map(int, stdin.readline().split(' '))
t = read_int()
for case_num in range(t):
	(n, x) = read_ints()
	w = list(read_ints())
	w.sort(reverse=True)
	dq = deque(w)
	ans = []
	acc = 0
	while dq:
		if acc + dq[0] != x:
			acc += dq[0]
			ans.append(dq.popleft())
		elif acc + dq[-1] != x:
			acc += dq[-1]
			ans.append(dq.pop())
		else:
			print('NO')
			break
	if len(ans) == n:
		print('YES')
		print(' '.join(map(str, ans)))


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
from itertools import accumulate
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
for _ in range(val()):
	(n, x) = li()
	l = li()
	l1 = [[i, l[i]] for i in range(n)]
	if sum(l) == x:
		print('NO')
		continue
	l1.sort(key=lambda x: -x[1])
	print('YES')
	l2 = [i[1] for i in l1]
	l3 = [l2[-1]] + l2[:-1]
	ans = l2
	for i in range(n):
		if sum(l2[:i + 1]) == x:
			ans = l3
			break
	print(*ans)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	w = sorted(map(int, input().split()))
	q = 0
	if sum(w) == x:
		print('NO')
		q += 1
	if q == 0:
		k = 0
		for j in range(n - 1):
			if k + w[j] != x:
				k += w[j]
			else:
				tmp = w[j]
				w[j] = w[j + 1]
				w[j + 1] = tmp
				break
		print('YES')
		print(*w)


import sys
input = sys.stdin.readline
out = []
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	if sum(w) == x:
		out.append('NO')
	else:
		out.append('YES')
		st = []
		for i in range(n):
			if w[-1] == x:
				a = w.pop()
				b = w.pop()
				w.append(a)
				w.append(b)
			y = w.pop()
			x -= y
			st.append(y)
		out.append(' '.join(map(str, st)))
print('\n'.join(out))


from collections import deque

def solve():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	dq = deque(a)
	ans = []
	while dq:
		if s + dq[0] == x:
			if s + dq[-1] == x:
				print('NO')
				return
			else:
				ans.append(dq[-1])
				s += dq[-1]
				dq.pop()
		else:
			ans.append(dq[0])
			s += dq[0]
			dq.popleft()
	print('YES')
	for i in ans:
		print(i, end=' ')
	print()
test = int(input())
for _ in range(test):
	solve()


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	impossible = False
	new = []
	total = 0
	while a:
		selected = a[-1]
		if total + selected != x:
			total += selected
			new.append(selected)
			del a[-1]
		else:
			selected = a[0]
			if total + selected != x:
				total += selected
				new.append(selected)
				del a[0]
			else:
				break
	if len(new) == n:
		print('YES')
		print(' '.join(map(str, new)))
	else:
		print('NO')


cases = int(input())
ans = ''
for y in range(cases):
	(n, x) = map(int, input().split(' '))
	w = list(map(int, input().split(' ')))
	if sum(w) == x:
		print('NO')
	else:
		arr = []
		check = x
		i = 0
		while i < n and w[i] != check:
			arr.append(w[i])
			check -= w[i]
			i += 1
		if i < n:
			arr.append(w[i + 1])
			arr.append(w[i])
			arr += w[i + 2:]
		print('YES')
		print(' '.join(map(str, arr)))


def solve(n, x, a):
	if sum(a) == x:
		return 'NO'
	s = 0
	for i in range(n):
		if s + a[i] == x:
			(a[i], a[i + 1]) = (a[i + 1], a[i])
		s += a[i]
	return 'YES\n' + ' '.join(map(str, a))
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	print(solve(n, x, a))


t = int(input())
while t > 0:
	l1 = []
	t -= 1
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	maxw = max(w)
	lol = sum(w)
	if maxw > x:
		w.remove(maxw)
		w.insert(0, maxw)
		l1 = w
		ans = 'YES'
	elif lol < x:
		l1 = w
		ans = 'YES'
	elif lol == x:
		l1 = w
		ans = 'NO'
	else:
		w = sorted(w)
		i = len(w) - 1
		som = 0
		l = 0
		while i >= 0:
			som += w[i]
			if som != x:
				l1.insert(l, w[i])
				l += 1
				i -= 1
			else:
				som -= w[i]
				l1.append(w[i])
				i -= 1
		ans = 'YES'
	print(ans)
	if ans == 'YES':
		for k in l1:
			print(k, end=' ')
		print()


def zip_sorted(a, b):
	return (zip(*sorted(zip(a, b)))[0], zip(*sorted(zip(a, b)))[1])

def gcd(a, b):
	return math.gcd(a, b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def ncr(n, r):
	return math.comb(n, r)

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def decimal_to_binary(n):
	return bin(n).replace('0b', '')

def binary_to_decimal(s):
	return int(s, 2)
import sys, os.path
import math
from collections import defaultdict, deque
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input1()))

def main():
	(t,) = I()
	for t1 in range(t):
		(n, x) = I()
		a = sorted(I())
		if sum(a) == x:
			print('NO')
		else:
			sum1 = 0
			i1 = -1
			for i in range(n):
				sum1 += a[i]
				if sum1 == x:
					i1 = i
					break
			if i1 != -1:
				temp = a[i1]
				a[i1] = a[-1]
				a[-1] = temp
			print('YES')
			print(*a)
main()


t = int(input())
while t > 0:
	t -= 1
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	w.sort()
	done = False
	for i in range(n):
		s = 0
		bad = False
		for y in w:
			s += y
			if s == x:
				bad = True
		if not bad:
			done = True
			break
		w = [w[-1]] + w[:-1]
	print('YES\n' + ' '.join((str(x) for x in w)) if done else 'NO')


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	w = sorted(map(int, input().split()))
	total = sum(w)
	if total == x:
		print('NO')
		continue
	print('YES')
	total = 0
	z = None
	a = []
	for val in w:
		total += val
		if total == x:
			z = val
		else:
			a.append(val)
	if z is not None:
		a.append(z)
	print(' '.join(map(str, a)))


import sys

def solve(a, n, x):
	if n == 1:
		return f'YES\n{a[0]}' if a[0] != x else 'NO'
	s = 0
	ans = True
	for i in range(n):
		s += a[i]
		if s == x:
			if i == n - 1:
				ans = False
			else:
				(a[i], a[i + 1]) = (a[i + 1], a[i])
			break
	if ans:
		return 'YES\n' + ' '.join(map(str, a))
	return 'NO'

def main():
	input = sys.stdin.readline
	print = sys.stdout.write
	res = ''
	t = int(input())
	for _ in range(t):
		(n, x) = map(int, input().split())
		a = list(map(int, input().split()))
		sub_res = solve(a, n, x)
		res += sub_res + '\n'
	print(res)
main()


from math import ceil
import sys

def solve():
	if sum(arr) == x:
		print('NO', flush=True)
		return None
	if sum(arr) < x:
		print('YES', flush=True)
		print(' '.join(map(str, arr)), flush=True)
		return None
	ans = 0
	for i in range(n - 1):
		ans += arr[i]
		if ans == x:
			(arr[i + 1], arr[i]) = (arr[i], arr[i + 1])
	print('YES', flush=True)
	print(' '.join(map(str, arr)), flush=True)
	return None
T = int(input())
for t in range(1, T + 1):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	solve()


t = int(input())
for i in range(t):
	nx = input()
	nx = nx.split(' ')
	n = int(nx[0])
	x = int(nx[1])
	array = input()
	array = array.split(' ')
	for j in range(n):
		array[j] = int(array[j])
	soma = 0
	for j in range(n):
		soma += array[j]
	if n == 1 and array[0] == x:
		print('NO')
	elif soma == x:
		print('NO')
	else:
		novo_array = array.copy()
		soma = 0
		trocou = False
		for k in range(n - 1):
			soma += novo_array[k]
			if soma == x:
				aux = novo_array[k + 1]
				novo_array[k + 1] = novo_array[k]
				novo_array[k] = aux
				trocou = True
				break
		ok = True
		soma = 0
		for k in range(n):
			soma += novo_array[k]
			if soma == x:
				ok = False
		if ok == True and trocou == True:
			print('YES')
			for l in range(n):
				novo_array[l] = str(novo_array[l])
			print(' '.join(novo_array))
		elif ok == True and trocou == False:
			print('YES')
			for l in range(n):
				array[l] = str(array[l])
			print(' '.join(array))


list1 = []
for i in range(int(input())):
	(n, x) = map(lambda j: int(j), input().split())
	w = list(sorted(map(lambda j: int(j), input().split()), reverse=True))
	if sum(w) == x:
		list1.append('NO')
	elif sum(w) < x:
		list1.append('YES')
		list1.append(' '.join(list(map(lambda y: str(y), w))))
	else:
		y = 0
		for j in range(n):
			y += w[j]
			if y > x:
				list1.append('YES')
				list1.append(' '.join(list(map(lambda y: str(y), w))))
				break
			elif y == x:
				y = w[j + 1]
				w[j + 1] = w[j]
				w[j] = y
				list1.append('YES')
				list1.append(' '.join(list(map(lambda y: str(y), w))))
				break
print(*list1, sep='\n')


t = int(input())
while t:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) == k:
		print('NO')
	else:
		print('YES')
		scalew = 0
		el = []
		for i in range(n):
			if scalew + arr[i] != k:
				scalew += arr[i]
			else:
				el.append(arr[i])
		for i in el:
			arr.remove(i)
		for i in el:
			arr.append(i)
		print(*arr)
	t -= 1


t = int(input())
for _ in range(t):
	(n, x) = [int(i) for i in input().split(' ')]
	arr = [int(i) for i in input().split(' ')]
	if x in arr and len(arr) == 1:
		print('NO')
	else:
		s = 0
		i = 0
		while i < len(arr):
			s += arr[i]
			if s == x:
				(arr[i], arr[(i + 1) % n]) = (arr[(i + 1) % n], arr[i])
			i += 1
		if s == x:
			print('NO')
		else:
			print('YES')
			print(*arr)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())), reverse=True)
	s = set()
	su = 0
	ans = []
	for i in range(n):
		if su + l[i] == k:
			s.add(l[i])
		else:
			su += l[i]
			ans.append(l[i])
	l = list(s)
	n = len(l)
	vis = [0] * n
	f = 1
	for i in range(n):
		f = 0
		for j in range(n):
			if su + l[j] != k and vis[j] != 1:
				su += l[j]
				f = 1
				ans.append(l[j])
				vis[j] = 1
				break
		if f == 0:
			print('NO')
			break
	if f == 1:
		print('YES')
		print(*ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) == x:
		print('NO')
	else:
		print('YES')
		count = 0
		for i in range(n - 1):
			count += arr[i]
			if count == x:
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
				count -= arr[i]
				count += arr[i + 1]
		print(*arr)


def fun(n, k, arr):
	arr.sort()
	if arr[len(arr) - 1] > k:
		return arr[::-1]
	else:
		arr = arr[::-1]
		n = len(arr)
		flag = False
		total = 0
		for i in range(n - 1):
			total += arr[i]
			if total == k:
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
				total += arr[i] - arr[i + 1]
		if total + arr[n - 1] == k:
			return -1
		else:
			return arr
for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = fun(n, k, arr)
	if ans != -1:
		print('YES')
		print(*ans)
	else:
		print('NO')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	arr = list(map(int, input().split()))
	k = sum(arr)
	if k == b:
		print('NO')
		continue
	else:
		su = 0
		ans = []
		for i in range(a):
			for j in range(a):
				if su + arr[j] != b and arr[j] != 0:
					ans.append(arr[j])
					su += arr[j]
					arr[j] = 0
					break
		if len(ans) != a:
			print('NO')
		else:
			print('YES')
			print(*ans)


t = int(input())

def solution(n, x, w):
	w.sort()
	total = sum(w)
	if total < x:
		return w
	elif total == x:
		return None
	res = []
	temp = 0
	while temp < x and len(w) > 0:
		if temp + w[-1] == x:
			res.append(w[0])
			temp += w[0]
			res.append(w[-1])
			temp += w[-1]
			w = w[1:-1]
		else:
			res.append(w[-1])
			temp += w[-1]
			w = w[:-1]
	res += w
	return res
for _ in range(t):
	(n, x) = [int(i) for i in input().split(' ')]
	w = [int(i) for i in input().split(' ')]
	res = solution(n, x, w)
	if res == None:
		print('NO')
	else:
		print('YES')
		print(' '.join([str(i) for i in res]))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	tot = sum(lst)
	if tot == x:
		print('NO')
	else:
		print('YES')
		cnt = 0
		for i in lst:
			if cnt + i != x:
				print(i, end=' ')
				cnt += i
			else:
				lst.append(i)
		print()


def main():
	t = int(input())
	for i in range(t):
		[n, x] = list(map(int, input().split()))
		w = list(map(int, input().split()))
		check = 0
		for j in range(n - 1):
			check += w[j]
			if check == x:
				(w[j], w[j + 1]) = (w[j + 1], w[j])
				break
		if check + w[n - 1] == x:
			print('NO')
		else:
			print('YES')
			print(' '.join(map(str, w)))
main()


tt = int(input())
for t in range(tt):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	if sum(arr) == x:
		print('NO')
	else:
		cur = 0
		for i in range(n):
			cur += arr[i]
			if cur == x:
				assert i != n - 1
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
				break
		print('YES')
		print(' '.join(list(map(str, arr))))


def is_perm_possible(aa, x):
	if all((a == aa[0] for a in aa)) and x % aa[0] == 0 and (x / aa[0] <= len(aa)):
		return (False, None)
	if sum(aa) == x:
		return (False, None)
	s = 0
	a2 = sorted(aa)
	n = len(a2)
	for i in range(n):
		s += a2[i]
		if s > x:
			return (True, a2)
		if s == x:
			if a2[-1] == a2[i]:
				assert a2[0] != a2[i]
				result = [a2[-1]] + a2[1:-1] + [a2[0]]
				return (True, result)
			else:
				result = a2[0:i] + [a2[-1]] + a2[i:-1]
				return (True, result)
	return (True, a2)
n_samples = int(input())
for t in range(n_samples):
	(n, x) = map(int, input().split(' '))
	aa = list(map(int, input().split(' ')))
	assert len(aa) == n
	(ok, perm) = is_perm_possible(aa, x)
	if ok:
		print('YES')
		print(' '.join(map(str, perm)))
	else:
		print('NO')


from sys import stdin

class IOI:

	def nextInt(self):
		return int(stdin.readline().strip())

	def Int(self):
		return map(int, stdin.readline().strip().split())

	def Str(self):
		return stdin.readline().strip()

	def Array(self):
		return list(map(int, stdin.readline().strip().split()))

def calculate(n, x, arr):
	totSum = sum(arr)
	if totSum == x:
		print('NO')
		return
	print('YES')
	curSum = 0
	i = 0
	while i < n:
		if curSum + arr[i] == x:
			if i < n - 1:
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
			else:
				(arr[i - 1], arr[i]) = (arr[i], arr[i - 1])
		curSum += arr[i]
		i += 1
	print(*arr)
input = IOI()
t = input.nextInt()
while t:
	(n, x) = input.Int()
	arr = input.Array()
	calculate(n, x, arr)
	t -= 1


def findans(a, arr):
	n = a[0]
	x = a[1]
	arr_final = []
	check_sum = 0
	arr.sort()
	num = -1
	for i in arr:
		if check_sum + i < x:
			arr_final.append(str(i))
			check_sum += i
		elif check_sum + i == x:
			num = arr.index(i)
		else:
			arr_final.append(str(i))
			check_sum += i
	if num != -1:
		arr_final.append(str(arr[num]))
		check_sum += arr[num]
	if check_sum == x:
		return ('NO', arr_final)
	else:
		return ('YES', arr_final)
t = int(input())
for i in range(t):
	a = list(map(int, input().strip().split()))[:2]
	arr = list(map(int, input().strip().split()))[:a[0]]
	(result, arr1) = findans(a, arr)
	print(result)
	if result == 'YES':
		print(' '.join(arr1))


import sys
input = sys.stdin.readline
for i in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) == x:
		print('NO')
	else:
		arr.sort()
		print('YES')
		s = 0
		temp = -1
		for i in range(n):
			if s + arr[i] != x:
				print(arr[i], end=' ')
				s += arr[i]
			else:
				temp = arr[i]
		if temp != -1:
			print(temp, end=' ')
		print()


z = [[]]
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	b = []
	c = []
	s = 0
	for i in a:
		s += i
		if s == x:
			s -= i
			b.append(i)
			continue
		c.append(i)
	s += sum(b)
	for i in b:
		c.append(i)
	if s != x:
		z.append('YES')
		d = ''
		for j in c:
			d += str(j) + ' '
		z.append(d)
	else:
		z.append('NO')
for i in range(1, len(z)):
	print(z[i])


t = int(input())
while t:
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	res_arr = []
	sum_ = 0
	if sum(arr) == x:
		print('NO')
		t -= 1
		continue
	i = 0
	while i < n:
		if sum_ + arr[i] == x:
			(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
			sum_ += arr[i]
			res_arr.append(arr[i])
			i += 1
		else:
			sum_ += arr[i]
			res_arr.append(arr[i])
			i += 1
		if sum_ > x:
			res_arr = res_arr + arr[i:]
			break
	print('YES')
	for i in res_arr:
		print(i, end=' ')
	t -= 1


for j in range(int(input())):
	(n, w) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	if sum(l) == w:
		print('NO')
	else:
		k = 0
		for i in range(n):
			k += l[i]
			if k == w:
				(l[i], l[i + 1]) = (l[i + 1], l[i])
		print('YES')
		print(' '.join(map(str, l)))


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	j = 0
	count = 0
	dump = []
	while j < len(arr):
		count += arr[j]
		if count == x:
			dump.append(arr[j])
			count -= arr[j]
			arr.remove(arr[j])
			j -= 1
		j += 1
	if len(dump) == 0:
		print('YES')
		print(*arr)
	else:
		k = 0
		flag = False
		while k < len(dump):
			count += dump[k]
			if count == x:
				flag = True
				break
			else:
				count += dump[k]
				arr.append(dump[k])
			k += 1
		if flag == True:
			print('NO')
		else:
			print('YES')
			print(*arr)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) == x:
		print('NO')
		continue
	l.sort()
	s = 0
	ctr = 'YES'
	for i in range(n):
		s += l[i]
		if s == x:
			if i < n - 1:
				(l[i], l[i + 1]) = (l[i + 1], l[i])
			else:
				ctr = 'NO'
	if ctr == 'NO':
		print('NO')
	else:
		print('YES', '\n', *l)


t = int(input())
for qweqwe in range(t):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	if sum(w) == x:
		print('NO')
		continue
	else:
		summ = 0
		for i in range(len(w) - 1):
			if summ + w[i] == x:
				(w[i], w[i + 1]) = (w[i + 1], w[i])
			summ += w[i]
	print('YES')
	print(' '.join(map(str, w)))


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	z = list(map(int, input().split()))
	a = 0
	l = []
	m = []
	for i in z:
		b = a + i
		if b == y:
			l.append(i)
		else:
			m.append(i)
			a += i
	c = m + l
	if a == 0:
		print('NO')
	elif sum(z) == y:
		print('NO')
	else:
		print('YES')
		print(*c)


def swapPositions(list, pos1, pos2):
	get = (list[pos1], list[pos2])
	(list[pos2], list[pos1]) = get
	return list

def solve():
	switch = False
	(n, x) = map(int, input().split())
	lista = list(map(int, input().split()))
	soma = 0
	index = 0
	for item in lista:
		soma += item
		if soma == x:
			switch = True
			break
		index += 1
	if switch:
		if len(lista) > index + 1:
			print('YES')
			print(*swapPositions(lista, index, index + 1), sep=' ')
		else:
			print('NO')
	else:
		print('YES')
		print(*lista, sep=' ')
n = int(input())
for i in range(n):
	solve()


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
import math as mt
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)
mod = int(1000000000.0) + 7

def power(k, n):
	if n == 0:
		return 1
	if n % 2:
		return power(k, n - 1) * k % mod
	t = power(k, n // 2)
	return t * t % mod

def totalPrimeFactors(n):
	count = 0
	if n % 2 == 0:
		count += 1
		while n % 2 == 0:
			n //= 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			count += 1
			while n % i == 0:
				n //= i
		i += 2
	if n > 2:
		count += 1
	return count

def main():
	for _ in range(int(input())):
		(n, x) = map(int, input().split())
		a = list(map(int, input().split()))
		if sum(a) == x:
			print('NO')
		else:
			print('YES')
			c = 0
			while len(a):
				if c + a[0] == x:
					a.append(a[0])
					a.pop(0)
				else:
					print(a[0], end=' ')
					c += a[0]
					a.pop(0)
			print('')
	return
main()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) == x or min(l) == max(l) == x:
		print('NO')
	elif sum(l) < x:
		print('YES')
		print(' '.join(map(str, l)))
	else:
		r = []
		total = 0
		while l:
			num = l[-1] + total
			if num == x:
				total += l[0]
				r.append(l[0])
				l.remove(l[0])
			else:
				total += l[-1]
				r.append(l.pop())
		print('YES')
		print(' '.join(map(str, r)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = []
	count = 0
	s = sum(l)
	if s == x:
		print('NO')
	else:
		print('YES')
		i = 0
		while i < n:
			if count + l[i] != x:
				ans.append(str(l[i]))
				count += l[i]
				i += 1
			else:
				ans.append(str(l[i + 1]))
				ans.append(str(l[i]))
				i += 2
		print(' '.join(ans))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	w.sort()
	res = []
	i = 0
	s = 0
	while i < n:
		s += w[i]
		if s == x:
			if i == n - 1:
				print('NO')
				break
			s -= w[i]
			w.append(w.pop(i))
		else:
			res.append(w[i])
			i += 1
	else:
		print('YES')
		print(*res)


import sys, math, bisect
inf = float('inf')
mod = 10 ** 9 + 7

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def tobinary(n):
	return bin(n)[2:]

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def SieveOfEratosthenes(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	if sum(arr) == k:
		print('NO')
	else:
		print('YES')
		ans = [-1] * n
		summ = 0
		for i in range(n):
			if summ + arr[i] == k:
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
				ans[i] = arr[i]
			else:
				ans[i] = arr[i]
			summ += arr[i]
		print(*ans)


from functools import reduce
m = int(input())
l = []
for _ in range(m):
	(t, b) = map(int, input().split())
	a = list(map(int, input().split()))
	u = []
	if sum(a) == b:
		l.append('NO')
	elif max(a) > b:
		u.append(max(a))
		a.remove(max(a))
		u = u + a
		l.append('YES')
		l.append(reduce(lambda x, y: str(x) + ' ' + str(y), u))
	else:
		k = []
		y = []
		f = 0
		for i in a:
			if f + i != b:
				y.append(i)
				f += i
			else:
				k.append(i)
		l.append('YES')
		l.append(reduce(lambda x, y: str(x) + ' ' + str(y), y + k))
for i in l:
	print(i)