Phoenix has $n$ blocks of height $h_1, h_2, \dots, h_n$, and all $h_i$ don't exceed some value $x$. He plans to stack all $n$ blocks into $m$ separate towers. The height of a tower is simply the sum of the heights of its blocks. For the towers to look beautiful, no two towers may have a height difference of strictly more than $x$.

Please help Phoenix build $m$ towers that look beautiful. Each tower must have at least one block and all blocks must be used.


-----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 three integers $n$, $m$, and $x$ ($1 \le m \le n \le 10^5$; $1 \le x \le 10^4$) — the number of blocks, the number of towers to build, and the maximum acceptable height difference of any two towers, respectively.

The second line of each test case contains $n$ space-separated integers ($1 \le h_i \le x$) — the heights of the blocks.

It is guaranteed that the sum of $n$ over all the test cases will not exceed $10^5$.


-----Output-----

For each test case, if Phoenix cannot build $m$ towers that look beautiful, print NO. Otherwise, print YES, followed by $n$ integers $y_1, y_2, \dots, y_n$, where $y_i$ ($1 \le y_i \le m$) is the index of the tower that the $i$-th block is placed in.

If there are multiple solutions, print any of them.


-----Examples-----

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


-----Note-----

In the first test case, the first tower has height $1+2+3=6$ and the second tower has height $1+2=3$. Their difference is $6-3=3$ which doesn't exceed $x=3$, so the towers are beautiful.

In the second test case, the first tower has height $1$, the second tower has height $1+2=3$, and the third tower has height $3$. The maximum height difference of any two towers is $3-1=2$ which doesn't exceed $x=3$, so the towers are beautiful.

Source: codeforces | Difficulty: MEDIUM
Tags: Greedy algorithms

Data structures

Constructive algorithms


Solutions:
t = int(input())
for i in range(t):
	(n, m, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst1 = []
	for j in range(n):
		lst1.append((lst[j], j))
	lst1.sort(key=lambda y: y[0])
	dic = {}
	for j in lst1:
		dic[j] = -1
	q = n // m
	ind = 0
	c = 1
	for h in range(q * m):
		dic[lst1[ind]] = c
		ind += 1
		c += 1
		if c > m:
			c = 1
	rem = n % m
	c = 1
	for h in range(rem):
		dic[lst1[ind]] = c
		ind += 1
		c += 1
	dic1 = {}
	for g in range(1, m + 1):
		dic1[g] = 0
	for h in dic.keys():
		dic1[dic[h]] += h[0]
	ma = -1000000000.0
	mi = 1000000000.0
	for h in dic1.values():
		if h > ma:
			ma = h
		if h < mi:
			mi = h
	if abs(ma - mi) > x:
		print('NO')
	else:
		print('YES')
		lst2 = []
		for h in range(n):
			lst2.append(0)
		for k in dic.keys():
			lst2[k[1]] = dic[k]
		print(*lst2)


from math import ceil, floor, log
for _ in range(int(input())):
	(n, m, x) = map(int, input().split(' '))
	arr = [int(w) for w in input().split(' ')]
	p = []
	for i in range(n):
		p.append([i, arr[i]])
	p.sort(key=lambda x: x[1])
	curr = 0
	res = [0] * n
	for item in p:
		res[item[0]] = curr % m + 1
		curr = curr + 1
	print('YES')
	for item in res:
		print(item, end=' ')
	print('')


import heapq
towerindex = 1

def main():
	global towerindex
	t = int(input())
	for _ in range(1, t + 1):
		towerindex = 1
		(n, m, x) = map(int, input().split())
		hs = list(map(int, input().split()))
		blocks = []
		for (index, h) in enumerate(hs):
			blocks.append(Block(h, index))
		blocks = sorted(blocks, reverse=True)
		towers = codeforces(m, x, blocks)
		if towers:
			print('YES')
			blocks = []
			for tower in towers:
				for bl in tower.blocks:
					bl.towerindex = tower.index
					blocks.append(bl)
			blocks = sorted(blocks, key=lambda x: x.index)
			print(' '.join(list(map(lambda x: str(x.towerindex), blocks))))
		else:
			print('NO')

def codeforces(m, x, blocks):
	towers = []
	for i in range(m):
		heapq.heappush(towers, tower(blocks.pop(0)))
	while blocks:
		tow = heapq.heappop(towers)
		tow.add(blocks.pop(0))
		heapq.heappush(towers, tow)
	return towers

class tower:

	def __init__(self, block):
		global towerindex
		self.height = block.height
		self.blocks = [block]
		self.index = towerindex
		towerindex += 1

	def __lt__(self, other):
		return self.height < other.height

	def __repr__(self):
		return str(self.index)

	def add(self, block):
		self.height += block.height
		self.blocks.append(block)

class Block:

	def __init__(self, h, index):
		self.height = h
		self.index = index

	def __repr__(self):
		return str(self.index)

	def __lt__(self, other):
		return self.height < other.height
main()


from collections import defaultdict
for _ in range(int(input())):
	(n, m, x) = list(map(int, input().split()))
	original = list(map(int, input().split()))
	array = original[:]
	array.sort()
	HT2 = defaultdict(list)
	mVal = 1
	for (idx, val) in enumerate(array):
		HT2[val].append([idx, mVal])
		mVal += 1
		if mVal > m:
			mVal = 1
	print('YES')
	for i in original:
		print(HT2[i][-1][1], end=' ')
		HT2[i].pop()
	print()


import bisect
import collections
import functools
import itertools
import math
import heapq
import random
import string

def repeat(_func=None, *, times=1):

	def decorator(func):

		@functools.wraps(func)
		def wrapper(*args, **kwargs):
			for _ in range(times):
				func(*args, **kwargs)
		return wrapper
	if _func is None:
		return decorator
	else:
		return decorator(_func)

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def getint():
	return int(input())

def getmatrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def display_matrix(mat):
	for i in range(len(mat)):
		print(mat[i])
	print('-' * 20)
MOD = 1000000007

@repeat(times=int(input()))
def main():
	(n, m, x) = unpack()
	arr = [(ht, i) for (i, ht) in enumerate(unpack())]
	arr.sort(reverse=True)
	tower = [(0, i + 1) for i in range(m)]
	out = [0] * n
	for (ht, i) in arr:
		(currht, idx) = tower[0]
		currht += ht
		out[i] = idx
		heapq.heapreplace(tower, (currht, idx))
	Max = max(tower, key=lambda x: x[0])[0]
	Min = min(tower, key=lambda x: x[0])[0]
	if Max - Min > x:
		print('NO')
		return
	print('YES')
	print(*out)
main()


import heapq
t = int(input())
for case in range(1, t + 1):
	(n, m, x) = [int(x) for x in input().split(' ')]
	heights = [int(x) for x in input().split(' ')]
	sorted_h = sorted(enumerate(heights), key=lambda x: x[1], reverse=True)
	heap = [(0, i) for i in range(m)]
	ans = [0] * n
	for (i, h) in sorted_h:
		(hh, mm) = heapq.heappop(heap)
		tow = (hh + h, mm)
		heapq.heappush(heap, tow)
		ans[i] = mm + 1
	if max(heap)[0] - min(heap)[0] > x:
		print('NO')
	else:
		print('YES')
		print(*ans)


import heapq
t = int(input())
for _ in range(t):
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	h = [[h[i], i] for i in range(n)]
	h.sort(key=lambda x: x[0], reverse=True)
	ans = [0 for i in range(n)]
	for i in range(m):
		ans[h[i][1]] = i + 1
	tower = [[h[i][0], i] for i in range(m)]
	heapq.heapify(tower)
	for i in range(m, n):
		(height, num) = heapq.heappop(tower)
		ans[h[i][1]] = num + 1
		heapq.heappush(tower, [height + h[i][0], num])
	(nin, nun) = heapq.heappop(tower)
	if tower:
		nax = max([ele[0] for ele in tower])
	else:
		nax = nin
	if nax - nin <= x:
		print('YES')
		print(*ans)
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase

def main():
	from heapq import heappush, heappop
	for _ in range(int(input())):
		(n, m, x) = map(int, input().split())
		a = list(map(int, input().split()))
		towerHeight = [0] * m
		loc = []
		h = []
		for i in range(m):
			heappush(h, (0, i))
		for i in range(n):
			c = heappop(h)
			loc.append(c[1] + 1)
			towerHeight[c[1]] += a[i]
			heappush(h, (towerHeight[c[1]], c[1]))
		print('YES')
		print(' '.join(map(str, loc)))
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin
from heapq import *
input = stdin.readline

def solve():
	(n, m, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	arr = [[0, i] for i in range(1, m + 1)]
	ans = [0] * n
	print('YES')
	if m == 1:
		return [1] * n
	for (ind, el) in enumerate(lst):
		temp = heappop(arr)
		temp[0] += el
		ans[ind] = temp[1]
		heappush(arr, temp)
	return ans
for test in range(int(input())):
	print(*solve())


def ii():
	return int(input())

def li():
	return [int(i) for i in input().split()]
for t in range(ii()):
	(n, m, x) = li()
	a = li()
	h = []
	for i in range(n):
		h.append([a[i], i])
	h.sort()
	ans = [0 for i in range(n)]
	for i in range(n):
		ans[h[i][1]] = i % m + 1
	print('YES')
	print(*ans)


def solve():
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	i = 0
	b = [0] * m
	ind = [-1] * n
	hai = [(h[i], i) for i in range(n)]
	hai.sort(key=lambda z: z[0])
	i = 0
	j = 0
	while j < n:
		while b[i] <= b[(i + 1) % m]:
			b[i] += hai[j][0]
			ind[hai[j][1]] = i + 1
			j += 1
			if j >= n:
				break
		i += 1
		i %= m
	for i in range(1, m):
		if b[i] - b[i - 1] > x:
			print('NO')
			return
	print('YES')
	for i in range(n):
		print(ind[i], end=' ')
	print()

def main():
	for _ in range(int(input())):
		solve()
main()


import heapq

class PQNode:

	def __init__(self, key, value) -> None:
		self.key = key
		self.value = value

	def __lt__(self, other):
		return self.value < other.value

	def __str__(self) -> str:
		return f'{self.key} : {self.value}'

def solve(n, m, x, lst):
	heap = [PQNode(i + 1, 0) for i in range(m)]
	res = [-1] * n
	for (i, ele) in enumerate(lst):
		min_tower = heapq.heappop(heap)
		min_tower.value += ele
		heapq.heappush(heap, min_tower)
		res[i] = min_tower.key
	print('YES')
	return ' '.join(map(str, res))
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	print(solve(n, m, x, lst))


for _ in range(int(input())):
	(n, m, x) = [int(x) for x in input().split()]
	h = [int(x) for x in input().split()]
	idx = sorted(range(n), key=lambda i: h[i])
	ans = [0] * n
	count = 0
	for i in idx:
		ans[i] = count + 1
		count = (count + 1) % m
	print('YES')
	print(*ans)


from collections import defaultdict
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = defaultdict(list)
	for i in range(n):
		d[a[i]].append(i)
	ans = [0] * m
	fans = [0] * n
	a.sort()
	r = 0
	for i in sorted(d.keys()):
		for j in range(len(d[i])):
			if r == m:
				r = 0
			ans[r] += i
			fans[d[i][j]] = r + 1
			r += 1
	if max(ans) - min(ans) > k:
		print('NO')
	else:
		print('YES')
		print(*fans)


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, m, x) = get_ints()
		h = get_list()
		data = []
		for i in range(n):
			data.append([h[i], i])
		data.sort()
		ans = [0] * n
		for i in range(n):
			ans[data[i][1]] = i % m + 1
		get_print('YES')
		get_print(' '.join(map(str, ans)))
solve()


import sys
import math
from math import factorial, inf, gcd, sqrt
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
from bisect import *
import random
sys.setrecursionlimit(10 ** 5)

def rarray():
	return [int(i) for i in input().split()]
t = 1
t = int(input())
for ii in range(t):
	(n, m, x) = rarray()
	a = rarray()
	a = [(j, i) for (i, j) in enumerate(a)]
	a.sort(reverse=True)
	ans = [0] * n
	pq = [(0, i) for i in range(m)]
	print('YES')
	for (i, j) in a:
		(v, c) = heappop(pq)
		ans[j] = c
		heappush(pq, (v + i, c))
	for i in ans:
		print(i + 1, end=' ')
	print()


for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	l = []
	j = 0
	for i in h:
		l.append([j, i])
		j += 1
	l.sort(key=lambda x: x[1])
	j = 0
	for k in l:
		k[1] = j % m + 1
		j += 1
	l.sort(key=lambda x: x[0])
	print('YES')
	print(*(i[1] for i in l))


from os import path
import sys, time, collections as c, math, pprint as p, itertools as it, operator as op, bisect as bs
(maxx, localsys, mod) = (float('inf'), 0, int(1000000000.0 + 7))
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	(a, ans) = (sorted(([i, idx] for (idx, i) in enumerate(list(map(int, input().split()))))), [0] * n)
	for i in range(n):
		ans[a[i][1]] = i % m + 1
	print('YES')
	print(*ans)


import heapq
for _ in range(int(input())):
	(n, m, x) = [int(i) for i in input().split()]
	h = [int(i) for i in input().split()]
	res = []
	towers = [(0, i) for i in range(1, m + 1)]
	heapq.heapify(towers)
	for (index, height) in enumerate(h):
		(h, i) = heapq.heappop(towers)
		res.append(i)
		heapq.heappush(towers, (height + h, i))
	print('YES')
	print(*res)


t = int(input())
for case in range(1, t + 1):
	(n, m, x) = (int(i) for i in input().split())
	h = [int(i) for i in input().split()]
	blocks = [[h[i], i, 0] for i in range(n)]
	blocks.sort(key=lambda x: x[0], reverse=True)
	towerHeights = [0 for _ in range(m)]
	t = 0
	for b in blocks:
		b[2] = t + 1
		towerHeights[t] += b[0]
		t = (t + 1) % m
	blocks.sort(key=lambda x: x[1])
	if max(towerHeights) - min(towerHeights) <= x:
		print('YES')
		for b in blocks:
			print(b[2], end=' ')
		print()
	else:
		print('NO')


import math
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().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	(n, m, x) = invr()
	flag = 1
	l = inlt()
	s = [[0, i] for i in range(m)]
	heapq.heapify(s)
	indx = []
	for i in range(n):
		(val, idx) = heapq.heappop(s)
		val = val + l[i]
		heapq.heappush(s, [val, idx])
		indx.append(idx + 1)
	s.sort()
	for i in range(m):
		if s[i][0] - s[i - 1][0] > x:
			flag = 0
	if flag:
		print('YES')
		print(*indx)
	else:
		print('NO')


import os
import sys
from math import *
from collections import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, m, x) = value()
	a = array()
	a = [(a[i], i) for i in range(n)]
	a.sort(reverse=True)
	ans = [0] * m
	id = [0] * n
	j = 0
	c = 1
	for i in range(n):
		ans[j] += a[i][0]
		id[a[i][1]] = j + 1
		j += c
		if j == m:
			j = m - 1
			c *= -1
		elif j == -1:
			j = 0
			c *= -1
	ok = 'YES'
	for i in range(1, m):
		if abs(ans[i] - ans[i - 1]) > x:
			ok = 'NO'
	if ok == 'NO':
		print(ok)
	else:
		print(ok)
		print(*id)


from heapq import heapify, heappush, heappop
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, m, x) = read_ints()
	h = list(read_ints())
	ans = [0] * n
	towers = [(0, i) for i in range(1, m + 1)]
	blocks = [(-h[i], i) for i in range(n)]
	heapify(blocks)
	while blocks:
		(block_height_neg, block_index) = heappop(blocks)
		block_height = -block_height_neg
		(tower_height, tower_index) = heappop(towers)
		ans[block_index] = tower_index
		heappush(towers, (tower_height + block_height, tower_index))
	if max(towers)[0] - min(towers)[0] <= x:
		print('YES')
		print(' '.join(map(str, ans)))
	else:
		print('NO')


from queue import PriorityQueue
from queue import Queue
import math
from collections import defaultdict
import sys
import operator as op
from functools import reduce
input = sys.stdin.readline
inp = lambda : list(map(int, input().split()))
(t,) = inp()
for _ in range(t):
	(n, m, x) = inp()
	q = inp()
	q = [(q[i], i) for i in range(n)]
	q.sort()
	ans = [None] * n
	for i in range(n):
		ans[q[i][1]] = i % m
	print('YES')
	for i in ans:
		print(i + 1, end=' ')
	print()


for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	for i in range(n):
		b.append([a[i], i])
	b.sort(reverse=True)
	ans = [1] * n
	while b:
		for i in range(m):
			if b:
				r = b.pop()
				ans[r[1]] = i + 1
	print('YES')
	print(*ans)


def solve(A, n, m, x):
	li = [(it, i) for (i, it) in enumerate(A)]
	li.sort()
	ans = [-1] * n
	oc = 0
	while li:
		t = []
		if oc % 2:
			t = li[:m]
			li = li[m:]
		else:
			for i in range(min(m, len(li))):
				t.append(li.pop())
		for (i, (v, ind)) in enumerate(t):
			ans[ind] = i + 1
	print('YES')
	print(*ans)
for case in range(int(input())):
	(n, m, x) = map(int, input().split())
	A = list(map(int, input().split()))
	solve(A, n, m, x)


t = int(input())
for _ in range(t):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = [0] * n
	arr = []
	for i in range(n):
		arr.append([a[i], i])
	arr.sort()
	for i in range(n):
		ans[arr[i][1]] = i % m + 1
	print('YES')
	print(*ans)


def answer(arr1, tower, x):
	arr1.sort(key=lambda x: x[0])
	result = [0 for i in range(tower)]
	result1 = [0 for i in range(len(arr))]
	i = 0
	j = 0
	while i < len(arr1):
		result[j] += arr1[i][0]
		result1[arr1[i][1]] = j + 1
		j += 1
		if j == tower:
			j = 0
		i += 1
	i = 0
	ind = True
	while i + 1 < tower:
		if abs(result[i] - result[i + 1]) > x:
			print('NO')
			ind = False
			break
		i += 1
	if ind == True:
		print('YES')
		for i in result1:
			print(i, end=' ')
		print()
t = int(input())
for w in range(t):
	inp = input().split()
	tower = int(inp[1])
	x = int(inp[2])
	inp = input().split()
	arr = []
	j = 0
	for i in inp:
		arr.append([int(i), j])
		j += 1
	answer(arr, tower, x)


import heapq

def main():
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	h = list(zip(h, range(n)))
	h.sort(reverse=True)
	ans = [0] * n
	q = []
	max_sum = 0
	for i in range(m):
		heapq.heappush(q, (h[i][0], i + 1))
		ans[h[i][1]] = i + 1
		max_sum = max(max_sum, h[i][0])
	for i in range(m, n):
		(sumh, mi) = heapq.heappop(q)
		heapq.heappush(q, (sumh + h[i][0], mi))
		ans[h[i][1]] = mi
		max_sum = max(max_sum, sumh + h[i][0])
	if max_sum - q[0][0] > x:
		print('NO')
	else:
		print('YES')
		print(*ans)
	return
t = int(input())
for _ in range(t):
	main()


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))

def takeSecond(elem):
	return elem[1]
t = sInt()
for _ in range(t):
	(n, m, x) = mInt()
	a = lInt()
	b = []
	for i in range(n):
		b.append([a[i], i])
	b.sort(reverse=True)
	d = 1
	flag = 1
	ms = [0 for i in range(m)]
	for i in range(n):
		ms[d - 1] += b[i][0]
		b[i][0] = d
		if flag == 1:
			d += 1
		else:
			d -= 1
		if d == m + 1:
			d = m
			flag = 0
		elif d == 0:
			d = 1
			flag = 1
	b.sort(key=takeSecond)
	ms.sort()
	if ms[-1] - ms[0] > x:
		print('NO')
	else:
		print('YES')
		for i in range(n):
			print(b[i][0], end=' ')
		print()


def indsort(s):
	li = []
	for i in range(len(s)):
		li.append([s[i], i])
	li.sort()
	sort_index = []
	for x in li:
		sort_index.append(x[1])
	return sort_index
t = int(input())
for _ in range(t):
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	ind = indsort(h)
	ans = [0] * n
	hei = [0] * m
	for i in range(n):
		if (i + 1) % m == 0:
			mod = m
		else:
			mod = (i + 1) % m
		ans[ind[i]] = mod
		hei[mod - 1] += h[ind[i]]
	if max(hei) - min(hei) > x:
		print('NO')
	else:
		print('YES')
		print(*ans)


def solve(n, m, x, h):
	ans = [-1] * n
	arr = sorted(((hi, i) for (i, hi) in enumerate(h)))
	for ind in range(n):
		ans[arr[ind][1]] = ind % m + 1
	print('YES')
	print(*ans)
T = int(input())
for t in range(T):
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	solve(n, m, x, h)


import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import itertools
import bisect
import heapq

def main():
	pass
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	i = 2
	while i * i <= n:
		if primes[i] == True:
			for j in range(i * i, n + 1, i):
				primes[j] = False
		i += 1
	pr = []
	for i in range(0, n + 1):
		if primes[i]:
			pr.append(i)
	return pr

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac

def sod(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s

def comp(a, b):
	c = 0
	for i in range(0, len(a)):
		if a[i] != b[i]:
			c += 1
	return c
for xyz in range(0, int(input())):
	(n, m, x) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(0, n):
		l[i] = [l[i], i]
	l.sort(reverse=True)
	ans = [-1] * n
	rev = True
	for i in range(0, n // m):
		rev = not rev
		num = i * m
		if rev:
			l[num:num + m] = reversed(l[num:num + m])
	rev = not rev
	if rev:
		l[num:] = reversed(l[num:])
	for i in range(0, n):
		pos = l[i][1]
		ans[pos] = 1 + i % m
	print('YES')
	print(*ans)


def get_ans(n, m, x, l):
	left = -1
	right = n
	check_ans = [0] * m
	ans_l = [-1] * n
	dir = 'l'
	while 1:
		check = False
		if left < right:
			if dir == 'l':
				curr_left = left
				for i in range(curr_left + 1, min(right, curr_left + 1 + m)):
					ans_l[l[i][1]] = i - curr_left
					check_ans[i - curr_left - 1] += l[i][0]
					left += 1
					check = True
				dir = 'r'
			elif dir == 'r':
				curr_right = right
				for i in range(curr_right - 1, max(curr_right - 1 - m, left), -1):
					ans_l[l[i][1]] = curr_right - i
					right -= 1
					check = True
					check_ans[curr_right - i - 1] += l[i][0]
				dir = 'l'
		if not check:
			break
	for i in range(1, m):
		if abs(check_ans[i] - check_ans[i - 1]) > x:
			return (False, ans_l)
	return (True, ans_l)
t = int(input())
for _ in range(t):
	(n, m, x) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(n):
		l[i] = [l[i], i]
	l.sort(key=lambda x: x[0])
	(check, ans) = get_ans(n, m, x, l)
	if check:
		print('YES')
		print(*ans)
	else:
		print('NO')


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	ans = [0] * n
	lst = sorted(range(n), key=lst.__getitem__)
	count = 1
	for i in range(n):
		if count > m:
			count = 1
		ans[lst[i]] = count
		count += 1
	print('YES')
	print(*ans)


import sys
from sys import stdin
import heapq
tt = int(stdin.readline())
for loop in range(tt):
	(n, m, X) = map(int, stdin.readline().split())
	h = list(map(int, stdin.readline().split()))
	q = [(0, i) for i in range(m)]
	ans = []
	for j in h:
		(x, ind) = heapq.heappop(q)
		ans.append(ind + 1)
		heapq.heappush(q, (x + j, ind))
	Ma = 0
	mi = float('inf')
	for (x, ind) in q:
		Ma = max(Ma, x)
		mi = min(mi, x)
	if Ma - mi <= X:
		print('YES')
		print(*ans)
	else:
		print('NO')


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	(n, m, x) = map(int, input().split())
	print('YES')
	a = list(map(int, input().split()))
	ans = [0] * n
	k = []
	for i in range(n):
		k.append((a[i], i))
	k.sort()
	counter = 0
	for i in range(n):
		(val, pos) = k[i]
		ans[pos] = counter + 1
		counter = (counter + 1) % m
	print(' '.join(map(str, ans)))


def read():
	number = eval(input())
	return number

def gets():
	s = input()
	return s

def cout(x):
	print(x)

def main():
	T = eval(input())
	while T:
		T = T - 1
		(n, m, x) = map(int, input().split())
		k = list(map(int, input().split()))
		dj = sorted(range(n), key=lambda i: k[i])
		ans = [0] * n
		cnt = 0
		for i in dj:
			ans[i] = cnt + 1
			cnt = (cnt + 1) % m
		cout('YES')
		print(*ans)
main()


for iii in range(int(input())):

	def solution(n, m, x, s):
		e = sorted([(s[i], i) for i in range(n)])
		d = [0 for i in range(n)]
		j = f = 1
		for i in range(n - 1, -1, -1):
			if j > m and f:
				j = 1
				f = 0
			elif j > m:
				j = 1
				f = 1
			if f:
				d[e[i][1]] = j
			else:
				d[e[i][1]] = m - j + 1
			j += 1
		return d
	(n, m, x) = map(int, input().split())
	s = list(map(int, input().split()))
	print('YES')
	print(*solution(n, m, x, s))


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default, func):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

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 countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	(n, m, x) = map(int, input().split())
	l = list(map(int, input().split()))
	l = [(l[i], i) for i in range(n)]
	l.sort()
	ans = [0] * m
	ind = [[] for i in range(n)]
	t = 0
	for i in range(n):
		ans[t % m] += l[i][0]
		ind[t % m].append(l[i][1])
		t += 1
	ans.sort()
	if ans[-1] - ans[0] > x:
		print('NO')
	else:
		print('YES')
		fi = [0] * n
		for i in range(m):
			for j in ind[i]:
				fi[j] = i + 1
		print(*fi)


for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	a1 = list(map(int, input().split()))
	a = []
	for i in range(n):
		a.append([a1[i], i])
	a.sort(reverse=True)
	move = 1
	ind = 0
	res = [0] * n
	print('YES')
	for i in range(n):
		if ind == -1:
			ind = 0
			move = 1
		elif ind == m:
			ind = m - 1
			move = -1
		res[a[i][1]] = ind + 1
		ind += move
	print(*res)


import math
import heapq as hq

def main():
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	tower_set = [(0, i) for i in range(m)]
	hq.heapify(tower_set)
	order = [0] * n
	for i in range(n):
		tower = hq.heappop(tower_set)
		h = a[i] + tower[0]
		order[i] = tower[1] + 1
		hq.heappush(tower_set, (h, tower[1]))
	print('YES')
	print(' '.join(map(str, order)))
t = int(input())
for i in range(t):
	main()


import heapq
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	l = [int(x) for x in input().split()]
	print('YES')
	heap = []
	for i in range(m):
		heap.append([0, i])
	heapq.heapify(heap)
	for i in range(n):
		result = heapq.heappop(heap)
		print(result[1] + 1, end=' ')
		result[0] += l[i]
		heapq.heappush(heap, result)
	print()


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
import heapq
for _ in range(t):
	(n, m, x) = map(int, input().split())
	H = list(map(int, input().split()))
	q = []
	A = []
	for (i, h) in enumerate(H):
		A.append((h, i))
	A.sort(key=lambda x: x[0])
	ans = [-1] * n
	for j in range(m):
		(h, i) = A.pop()
		ans[i] = j + 1
		q.append((h, j + 1))
	heapq.heapify(q)
	while A:
		(h, p) = heapq.heappop(q)
		(a, i) = A.pop()
		h += a
		ans[i] = p
		heapq.heappush(q, (h, p))
	S = [0] * m
	for i in range(n):
		S[ans[i] - 1] += H[i]
	mins = min(S)
	maxs = max(S)
	if maxs - mins <= x:
		print('YES')
		print(*ans)
	else:
		print('NO')


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(1, inp() + 1):
	(n, m, k) = ip()
	x = ip()
	xx = sorted(x)
	y = [[] for i in range(m)]
	mind = m - 1
	for i in range(n - 1, n - m - 1, -1):
		for j in range(i, -1, -m):
			y[mind].append(xx[j])
		mind -= 1
	w = [sum(i) for i in y]
	ans = 'YES'
	for i in range(1, m):
		if abs(w[i] - w[i - 1]) > k:
			ans = 'NO'
			break
	if ans == 'NO':
		print(ans)
		continue
	dt = {}
	for i in x:
		dt[i] = []
	for i in range(m):
		for j in y[i]:
			dt[j].append(i)
	z = [0] * n
	for i in range(n):
		z[i] = dt[x[i]].pop(-1) + 1
	print(ans)
	print(*z)


for i in range(int(input())):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	res = sorted([(a[i], i) for i in range(n)])
	ans = [0] * n
	for i in range(n):
		ans[res[i][1]] = i % m + 1
	print('YES')
	print(*ans)


import heapq
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	zoop = list(map(int, input().split()))
	kk = [(0, i) for i in range(m)]
	ans = [0] * n
	j = n - 1
	while zoop:
		el = zoop.pop()
		(a, ind) = heapq.heappop(kk)
		heapq.heappush(kk, (a + el, ind))
		ans[j] = ind + 1
		j -= 1
	print('YES')
	print(*ans)


from sys import stdin
import math
lst = list(map(int, stdin.read().split()))
_s = 0

def inp(n=1):
	global _s
	ret = lst[_s:_s + n]
	_s += n
	return ret

def inp1():
	return inp()[0]
t = inp1()
for _ in range(t):
	n = inp1()
	m = inp1()
	x = inp1()
	y = inp(n)
	b = []
	for i in range(n):
		b.append([y[i], i])
	b = sorted(b, key=lambda x: x[0], reverse=True)
	t = []
	for i in range(0, n, m):
		t.append(b[i:i + m])
		if len(t) % 2 != 0:
			t[-1] = sorted(t[-1], key=lambda x: x[0])
	s = [0] * m
	for j in range(m):
		for i in t:
			if j < len(i):
				s[j] += i[j][0]
	status = 'YES'
	for i in range(1, m):
		if s[i] - s[i - 1] > x:
			status = 'NO'
			break
	print(status)
	if status == 'YES':
		r = []
		for j in range(m):
			r.append([])
			for i in t:
				if j < len(i):
					r[j].append(i[j])
		for i in range(m):
			for j in r[i]:
				j[0] = i + 1
		fin = []
		for i in r:
			fin += i
		fin = sorted(fin, key=lambda x: x[1])
		for i in fin:
			print(i[0], end=' ')
		print()


from collections import defaultdict
import heapq
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	h = [int(i) for i in input().split()]
	heap = []
	for order_num in range(1, m + 1):
		heapq.heappush(heap, [0, order_num])
	towers = []
	for (ind, h_i) in enumerate(h):
		pair = heapq.heappop(heap)
		towers.append(pair[1])
		pair[0] += h_i
		heapq.heappush(heap, pair)
	print('YES')
	print(*towers)


import heapq
from sys import *
from collections import defaultdict as dd
from heapq import *
from math import *
from bisect import *

def sinp():
	return input()

def inp():
	return int(sinp())

def minp():
	return map(int, sinp().split())

def linp():
	return list(minp())

def strl():
	return list(sinp())

def pr(x):
	print(x)
mod = int(1000000000.0 + 7)
for _ in range(inp()):
	(n, m, x) = minp()
	h = linp()
	d = []
	for i in range(m):
		heappush(d, [0, i + 1])
	for i in range(n):
		h[i] = [h[i], i]
	h.sort()
	res = [0 for i in range(n)]
	for i in range(n - 1, -1, -1):
		t = heappop(d)
		res[h[i][1]] = t[1]
		t[0] += h[i][0]
		heappush(d, t)
	(a, b) = (-maxsize, maxsize)
	for i in range(m):
		t = heappop(d)
		a = max(a, t[0])
		b = min(b, t[0])
	if a - b <= x:
		pr('YES')
		print(*res)
	else:
		pr('NO')


import heapq

def solve(n, m, x, lst):
	heap = [(0, i + 1) for i in range(m)]
	res = [-1] * n
	for (i, ele) in enumerate(lst):
		(tower_height, tower_index) = heapq.heappop(heap)
		tower_height += ele
		heapq.heappush(heap, (tower_height, tower_index))
		res[i] = tower_index
	print('YES')
	return ' '.join(map(str, res))
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	print(solve(n, m, x, lst))


from sys import stdin
import math
lst = list(map(int, stdin.read().split()))
_s = 0

def inp(n=1):
	global _s
	ret = lst[_s:_s + n]
	_s += n
	return ret

def inp1():
	return inp()[0]
t = inp1()
for _ in range(t):
	n = inp1()
	m = inp1()
	x = inp1()
	y = inp(n)
	b = [[y[i], i] for i in range(n)]
	b = sorted(b, key=lambda x: x[0], reverse=True)
	ret = [0] * n
	for i in range(n):
		ret[b[i][1]] = i % m + 1
	print('YES')
	for i in ret:
		print(i, end=' ')
	print()


import sys
input = sys.stdin.readline
import heapq
(T,) = map(int, input().split())
for _ in range(T):
	(N, M, X) = map(int, input().split())
	hs = list(map(int, input().split()))
	hs = [(i, hs[i]) for i in range(N)]
	hs = sorted(hs, key=lambda x: x[1])[::-1]
	a = [(0, i) for i in range(M)]
	heapq.heapify(a)
	R = [0] * N
	while hs:
		(s, i) = heapq.heappop(a)
		(j, x) = hs.pop()
		heapq.heappush(a, (s + x, i))
		R[j] = i + 1
	print('YES')
	print(*R)


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby
for _ in range(II()):
	(n, m, x) = LI()
	a = LI()
	b = []
	for (i, j) in enumerate(a):
		b.append((j, i))
	b.sort(reverse=True)
	ans = [0] * n
	c = [(0, i) for i in range(m)]
	heapify(c)
	for i in range(n):
		pop = heappop(c)
		heappush(c, (pop[0] + b[i][0], pop[1]))
		ans[b[i][1]] = pop[1] + 1
	print('YES')
	print(*ans)


from sys import stdin, stdout
import math
import heapq

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, m, x) = mi()
	l1 = li()
	ans = [0] * n
	heapp = [[0, x] for x in range(1, m + 1)]
	heapq.heapify(heapp)
	for i in range(n):
		node = heapq.heappop(heapp)
		ans[i] = node[1]
		node[0] += l1[i]
		heapq.heappush(heapp, node)
	print('YES')
	print(*ans)


from collections import defaultdict, deque
from heapq import heappush, heappop
from math import inf
ri = lambda : map(int, input().split())

def solve():
	(n, m, x) = ri()
	A = list(ri())
	heap = []
	print('YES')
	for i in range(m):
		heappush(heap, (0, i + 1))
	for j in range(len(A)):
		(sm, idx) = heappop(heap)
		print(idx, end=' ')
		heappush(heap, (sm + A[j], idx))
	print()
t = 1
t = int(input())
while t:
	t -= 1
	solve()


import heapq

def solve(amount, diff, arr):
	blocks = sorted(enumerate(arr), reverse=True, key=lambda x: x[1])
	towers = [[0, i + 1] for i in range(amount)]
	res = [0] * len(arr)
	for (idx, block) in blocks:
		tower = heapq.heappop(towers)
		tower[0] += block
		res[idx] = tower[1]
		heapq.heappush(towers, tower)
	return res
for _ in '_' * int(input()):
	(_, amount, diff) = map(int, input().split())
	result = solve(amount, diff, [*map(int, input().split())])
	print(['NO', 'YES'][bool(result)])
	if result != None:
		print(*result)


from heapq import heapify, heappush, heappop
for _ in range(int(input())):
	(n, m, x) = [int(i) for i in input().split()]
	heap = []
	heapify(heap)
	for i in range(m):
		heappush(heap, [0, i + 1])
	a = []
	b = [int(i) for i in input().split()]
	for i in range(len(b)):
		a.append([b[i], i])
	res = [0] * n
	a.sort()
	for i in range(n - 1, -1, -1):
		p = heappop(heap)
		res[a[i][1]] = p[1]
		p[0] += a[i][0]
		heappush(heap, p)
	(maxi, mini) = (0, 1000000000004)
	for i in range(m):
		p = heappop(heap)
		maxi = max(maxi, p[0])
		mini = min(mini, p[0])
	if maxi - mini <= x:
		print('YES')
		for i in res:
			print(i, end=' ')
		print('')
	else:
		print('NO')


import heapq
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	h = list(map(lambda x: (0, x), range(m)))
	heapq.heapify(h)
	pos = [-1] * n
	a = list(enumerate(a))
	a.sort(key=lambda x: -x[1])
	(minv, maxv) = (float('inf'), -float('inf'))
	for (aindex, avalue) in a:
		(wt, idx) = heapq.heappop(h)
		pos[aindex] = idx + 1
		value = wt + avalue
		minv = min(minv, value)
		maxv = min(maxv, value)
		heapq.heappush(h, (value, idx))
	if maxv - minv > x:
		print('NO')
	else:
		print('YES')
		print(*pos)


import sys
import heapq
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, M, X) = [int(x) for x in input().split()]
		H = [int(x) for x in input().split()]
		ans = [0] * N
		value = []
		for (i, v) in enumerate(H):
			value.append([v, i])
		value.sort(reverse=True)
		hq = []
		for i in range(M):
			heapq.heappush(hq, (0, i + 1))
		for (v, i) in value:
			(ch, cm) = heapq.heappop(hq)
			heapq.heappush(hq, (ch + v, cm))
			ans[i] = cm
		ma = 0
		mi = float('inf')
		while hq:
			(ci, cm) = heapq.heappop(hq)
			ma = max(ci, ma)
			mi = min(ci, ma)
		if abs(ma - mi) <= X:
			print('YES')
			print(*ans)
		else:
			print('NO')
main()


for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	a = sorted(zip(map(int, input().split()), [i for i in range(n)]))
	loc = [0] * n
	for i in range(n):
		loc[a[i][1]] = i % m + 1
	print('YES')
	print(*loc)


import heapq
t = int(input())
for _ in range(t):
	(n, m, x) = map(int, input().split())
	hs = [int(i) for i in input().split()]
	hs = [(num, i) for (i, num) in enumerate(hs)]
	q = []
	heapq.heapify(q)
	for i in range(m):
		q.append((0, i + 1))
	hs.sort()
	res = [0] * n
	while hs:
		(height, tower) = heapq.heappop(q)
		(h, i) = hs.pop()
		height += h
		res[i] = tower
		heapq.heappush(q, (height, tower))
	mn = min(q)
	mx = max(q)
	if mx[0] - mn[0] > x:
		ans = 'NO'
	else:
		ans = 'YES'
	print(ans)
	if ans == 'YES':
		print(*res)


import sys
import math
mod = 10 ** 9 + 7
LI = lambda : [int(k) for k in input().split()]
input = lambda : sys.stdin.readline().rstrip()
IN = lambda : int(input())
S = lambda : input()
for t in range(IN()):
	(n, m, x) = LI()
	h = LI()
	hh = []
	for i in range(n):
		hh.append([h[i], i])
	hh.sort()
	ans = [0] * n
	for i in range(n):
		ans[hh[i][1]] = i % m + 1
	print('YES')
	print(*ans)


import sys
input = sys.stdin.readline
import math
mod = 10 ** 9 + 7

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())
for _ in range(inp()):
	(n, m, x) = invr()
	l = inlt()
	if n == 1:
		print('YES')
		print(1)
		continue
	a = []
	out = []
	for i in range(n):
		a.append([l[i], i + 1])
	a.sort(key=lambda x: x[0])
	b = [i + 1 for i in range(m)]
	c = [m - i for i in range(m)]
	z = 0
	h = [[0, i + 1] for i in range(m)]
	p = 0
	for i in range(n // m):
		if z == 0:
			out.extend(b)
			for j in range(m):
				h[j][0] += a[p][0]
				p += 1
			z = 1
		else:
			out.extend(c)
			for j in range(m):
				h[m - 1 - j][0] += a[p][0]
				p += 1
			z = 0
	h.sort(key=lambda x: x[0])
	for i in range(n % m):
		out.append(h[n % m - 1 - i][1])
	o = [0 for i in range(n)]
	for i in range(n):
		o[a[i][1] - 1] = out[i]
	d = [0 for i in range(m)]
	for i in range(n):
		d[o[i] - 1] += l[i]
	d.sort()
	f = 1
	if d[-1] - d[0] > x:
		f = 0
	if f == 0:
		print('NO')
	else:
		print('YES')
		print(*o)


for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	l = list(map(int, input().split()))
	a = [[l[i], i] for i in range(n)]
	a.sort()
	out = [0] * n
	for i in range(n):
		out[a[i][1]] = i % m + 1
	print('YES')
	print(*out)


import heapq
T = int(input())
for testcase in range(1, T + 1):
	(n, m, x) = list(map(int, input().split()))
	h = list(map(int, input().split()))
	heap = []
	for i in range(m):
		heapq.heappush(heap, (0, i + 1))
	res = []
	for height in h:
		min = heapq.heappop(heap)
		res.append(min[1])
		heapq.heappush(heap, (min[0] + height, min[1]))
	min = heapq.heappop(heap)
	if min[0] > 0:
		print('YES')
		print(*res)
	else:
		print('NO')


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = [a[i], i]
	a.sort()
	ans = defaultdict(list)
	for i in range(n):
		ans[a[i][1]] = i % m
	print('YES')
	v = [0] * n
	for i in range(n):
		v[i] = ans[i] + 1
	print(*v)


import heapq
for _ in range(int(input())):
	(n, m, x) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	k = []
	for i in range(n):
		k.append([l[i], i])
	k.sort()
	h = [[0, i] for i in range(m)]
	a = [0] * n
	for i in range(n):
		(c, d) = heapq.heappop(h)
		c += k[i][0]
		a[k[i][1]] = d + 1
		heapq.heappush(h, [c, d])
	j = min(h, key=lambda s: s[0])[0]
	o = max(h, key=lambda s: s[0])[0]
	if o - j <= c:
		print('YES')
		print(' '.join(map(str, a)))
	else:
		print('NO')


import sys, heapq
input = sys.stdin.buffer.readline

def map_int():
	return map(int, input().split())

def solve():
	(n, m, x) = map_int()
	h = list(map_int())
	ans = [0] * n
	q = []
	for i in range(m):
		heapq.heappush(q, (h[i], i))
		ans[i] = i
	for i in range(m, n):
		(cur, ind) = heapq.heappop(q)
		ans[i] = ind
		heapq.heappush(q, (cur + h[i], ind))
	print('YES')
	for x in ans:
		print(x + 1, end=' ')
	print()
for _ in range(int(input())):
	solve()


from collections import defaultdict
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	A = list(map(int, input().split()))
	ans = [0] * m
	s = []
	for i in range(n):
		s.append((A[i], i))
	s.sort(key=lambda x: (x[0], x[1]))
	j = 0
	for i in range(n):
		ans[j] += s[i][0]
		j = (j + 1) % m
	if max(ans) - min(ans) > x:
		print('NO')
	else:
		print('YES')
		out = [0] * n
		j = 1
		for i in range(n):
			if j == m + 1:
				j = 1
			out[s[i][1]] = j
			j += 1
		print(*out)


import os
import sys
from array import array
from bisect import bisect_right
from collections import Counter, defaultdict
from io import BytesIO, IOBase
from math import gcd, inf, sqrt, ceil, floor
sys.setrecursionlimit(2 * 10 ** 5)

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

def sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def getFactorization(x):
	ret = set()
	while x != 1:
		ret.add(spf[x])
		x = x // spf[x]
	return ret

def printDivisors(n):
	i = 2
	z = [1, n]
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				z.append(i)
			else:
				z.append(i)
				z.append(n // i)
		i = i + 1
	return z

def create(n, x, f):
	pq = len(bin(n)[2:])
	if f == 0:
		tt = min
	else:
		tt = max
	dp = [[inf] * n for _ in range(pq)]
	dp[0] = x
	for i in range(1, pq):
		for j in range(n - (1 << i) + 1):
			dp[i][j] = tt(dp[i - 1][j], dp[i - 1][j + (1 << i - 1)])
	return dp

def enquiry(l, r, dp, f):
	if l > r:
		return inf if not f else -inf
	if f == 1:
		tt = max
	else:
		tt = min
	pq1 = len(bin(r - l + 1)[2:]) - 1
	return tt(dp[pq1][l], dp[pq1][r - (1 << pq1) + 1])

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 * p, n + 1, p):
				prime[i] = False
		p += 1
	x = []
	for i in range(2, n + 1):
		if prime[i]:
			x.append(i)
	return x

def main():
	for _ in range(int(input())):
		(n, m, x) = map(int, input().split())
		a = [int(x) for x in input().split()]
		for i in range(n):
			a[i] = (a[i], i)
		a.sort()
		xx = 0
		dp = [0] * m
		an = [0] * n
		while xx < n:
			for i in range(m):
				dp[i] += a[xx][0]
				an[a[xx][1]] = i + 1
				xx += 1
				if xx == n:
					break
		if max(dp) - min(dp) > x or 0 in dp:
			print('NO')
		else:
			print('YES')
			print(*an)
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import heapq
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	h = []
	for i in range(n):
		h.append((a[i], i))
		a[i] = 0
	heapq.heapify(h)
	while h:
		for i in range(1, m + 1):
			if h:
				(ele, idx) = heapq.heappop(h)
				a[idx] = i
			else:
				break
	print('YES')
	print(*a)


import sys
from heapq import *
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	heap = []
	for i in range(m):
		heappush(heap, [0, i + 1])
	for i in range(n):
		h[i] = [h[i], i]
	h = sorted(h)
	res = [-1 for i in range(n)]
	i = n - 1
	while i >= 0:
		node = heappop(heap)
		res[h[i][1]] = node[1]
		node[0] += h[i][0]
		heappush(heap, node)
		i -= 1
	(ma, mb) = (-sys.maxsize, sys.maxsize)
	for i in range(m):
		node = heappop(heap)
		ma = max(ma, node[0])
		mb = min(mb, node[0])
	if ma - mb <= x:
		print('YES')
		print(*res)
	else:
		print('NO')


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, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	temp = []
	ans = []
	for i in range(n):
		temp.append([h[i], i])
		ans.append(0)
	temp.sort()
	for i in range(n):
		k = i % m + 1
		ans[temp[i][1]] = k
	print('YES')
	print(*ans)


for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	a = [*map(int, input().split())]
	s = sorted(range(n), key=lambda i: a[i])
	ans = [0] * n
	c = 0
	for i in s:
		ans[i] = c + 1
		c = (c + 1) % m
	print('YES')
	print(*ans)


T = int(input())
for t in range(T):
	(n, m, x) = map(int, input().split())
	hs = list(map(int, input().split()))
	hs = [(hs[i], i) for i in range(n)]
	ord = [0] * n
	hs.sort()
	(i, j) = (0, 0)
	arr = [0] * m
	while i < n:
		arr[j] += hs[i][0]
		if abs(arr[j] - arr[j - 1]) > x:
			break
		ord[hs[i][1]] = j + 1
		j = (j + 1) % m
		i += 1
	if i == n:
		print('YES')
		for i in ord:
			print(i, end=' ')
		print()
	else:
		print('NO')


import sys
import bisect
from bisect import bisect_left as lb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)

def hnbhai():
	(n, m, x) = sd()
	a = sd()
	d = []
	for i in range(n):
		d.append([a[i], i])
	d.sort()
	ans = [-1] * n
	ans2 = [0] * m
	for i in range(m):
		ans[d[n - i - 1][1]] = i + 1
		ans2[i] += d[n - i - 1][0]
	ind = 1
	for i in range(n - m):
		ans[d[i][1]] = ind
		ans2[ind - 1] += d[i][0]
		ind += 1
		if ind > m:
			ind = 1
	if max(ans2) - min(ans2) > x:
		print('NO')
	print('YES')
	print(*ans)
for _ in range(sb()):
	hnbhai()


n = int(input())
for i in range(n):
	(n, m, x) = map(int, input().split())
	s = list(map(int, input().split()))
	li = []
	for i in range(len(s)):
		li.append([s[i], i])
	li.sort()
	sort_index = []
	for x in li:
		sort_index.append(x[1])
	Ans = [0] * n
	cnt = -1
	for j in sort_index:
		cnt += 1
		Ans[j] = cnt % m + 1
	print('YES')
	print(' '.join((str(i) for i in Ans)))


from heapq import heappop, heappush, heapify
t = int(input())
for tt in range(t):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	h = [[a[r], r + 1] for r in range(m)]
	print('YES')
	print(' '.join([str(i + 1) for i in range(m)]), end=' ')
	heapify(h)
	for j in range(m, n):
		o = heappop(h)
		o[0] += a[j]
		print(o[1], end=' ')
		heappush(h, o)
	print()


for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [[a[i], i] for i in range(n)]
	b.sort()
	b.reverse()
	res = [0] * n
	c = 0
	for i in range(n):
		k = b[i][1]
		res[k] = c % m + 1
		c += 1
	print('YES')
	print(*res)


import heapq
for _ in range(int(input())):
	h = []
	(n, t, x) = map(int, input().split())
	heapq.heapify(h)
	for i in range(t):
		heapq.heappush(h, (0, i))
	dic = {}
	lis = list(map(int, input().split()))
	print('YES')
	for i in range(len(lis)):
		(a, b) = heapq.heappop(h)
		dic[i] = b
		heapq.heappush(h, (a + lis[i], b))
	for i in range(len(lis)):
		print(dic[i] + 1, end=' ')
	print()


import heapq

def solve():
	(n, m, x) = map(int, input().split())
	heights = list(map(int, input().split()))
	heap = [(0, i + 1) for i in range(m)]
	res = [-1] * n
	for (i, h) in enumerate(heights):
		(tower_height, idx) = heapq.heappop(heap)
		tower_height += h
		heapq.heappush(heap, (tower_height, idx))
		res[i] = idx
	print('YES')
	print(*res)
t = int(input())
for _ in range(t):
	solve()


import sys
import math
from bisect import bisect_left
from collections import Counter, defaultdict
L = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input()
mod = 10 ** 9 + 7

def solve():
	(n, m, z) = L()
	a = L()
	a = [(a[i], i) for i in range(n)]
	h = [0] * m
	ans = [0] * n
	a.sort()
	j = n - 1
	c = 0
	t = 1
	while n > c:
		if t == 0:
			for x in range(m - 1, -1, -1):
				h[x] += a[j][0]
				ans[a[j][1]] = x + 1
				j -= 1
				c += 1
				if c == n:
					break
			t = 1
		elif t == 1:
			for x in range(m):
				h[x] += a[j][0]
				ans[a[j][1]] = x + 1
				j -= 1
				c += 1
				if c == n:
					break
			t = 0
	if abs(max(h) - min(h)) > z:
		print('NO')
		return
	print('YES')
	print(*ans)
for _ in range(I()):
	solve()


from math import floor
from math import sqrt
from math import ceil
from itertools import combinations, accumulate, groupby, count
from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from os import *
from re import *

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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			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:
			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')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))

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

def zzz():
	return [int(i) for i in fast().split()]
(z, zz) = (fast, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer, end='\n'):
	stdout.write(str(answer) + end)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
num = int(z())
for _ in range(num):
	(n, m, x) = zzz()
	arr = zzz()
	newArr = [(j, i) for (i, j) in enumerate(arr)]
	newArr = sorted(newArr)
	lst = [[0, []] for i in range(m)]
	for (i, j) in enumerate(newArr):
		lst[i % m][0] += j[0]
		lst[i % m][1].append(j[1])
	if lst[-1][0] - lst[0][0] > x:
		print('NO')
		continue
	print('YES')
	ans = [0] * n
	for (i, j) in enumerate(lst):
		for k in j[1]:
			ans[k] = i + 1
	print(*ans)


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
import math
t = int(input())
for _ in range(t):
	(n, m, x) = map(int, input().split())
	aa = list(map(int, input().split()))
	a = []
	for i in range(len(aa)):
		a.append((aa[i], i + 1))
	a.sort()
	towers = [0] * m
	idx = [-1] * n
	for i in range(n):
		tw = i % m
		idx[a[i][1] - 1] = tw + 1
		towers[tw] += a[i][0]
	if max(towers) - min(towers) <= x:
		print('YES')
		print(' '.join(map(str, idx)))
	else:
		print('NO')


from sys import stdin, stdout
from math import sqrt, inf, hypot
from copy import copy
from heapq import heappop, heapify, heappush
from _collections import deque
t = int(stdin.readline())
for _ in range(t):
	(n, m, k) = map(int, stdin.readline().split())
	a = [int(x) for x in stdin.readline().split()]
	for i in range(n):
		a[i] = (a[i], i)
	a.sort(key=lambda p: p[0], reverse=True)
	ans = [-1] * n
	heap = []
	for i in range(m):
		heap.append((0, i))
	heapify(heap)
	for i in range(n):
		(cnt, tower) = heappop(heap)
		(cost, num) = a[i]
		ans[num] = tower
		heappush(heap, (cnt + cost, tower))
	mn = 1000000000000.0
	mx = 0
	for x in heap:
		if x[0] < mn:
			mn = x[0]
		if x[0] > mx:
			mx = x[0]
	if mx - mn <= k:
		stdout.write('YES\n')
		for i in ans:
			stdout.write(str(i + 1) + ' ')
		stdout.write('\n')
	else:
		stdout.write('NO\n')


import itertools

def readline():
	return map(int, input().split())

def solve_clever():
	(n, m, x) = readline()
	h = sorted(((hi, i) for (i, hi) in enumerate(readline())))
	answer = sorted(((i, tower_idx) for ((hi, i), tower_idx) in zip(h, itertools.cycle(range(1, m + 1)))))
	print('YES')
	print(*(ti for (i, ti) in answer))

def main():
	t = int(input())
	for __ in range(t):
		solve_clever()
main()


from collections import defaultdict, deque, Counter
from functools import lru_cache, reduce
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
from random import randint
from fractions import Fraction as frac
import math
import operator
import sys
hpop = heappop
hpush = heappush
MOD = 10 ** 9 + 7

def solution():
	(n, m, x) = map(int, input().split())
	arr = map(int, input().split())
	arr = [(val, i) for (i, val) in enumerate(arr)]
	arr.sort()
	min_heap = []
	for tower in range(m):
		heappush(min_heap, (0, tower))
	res = [-1] * n
	for (val, i) in arr:
		(tower_height, tower) = heappop(min_heap)
		res[i] = tower + 1
		heappush(min_heap, (tower_height + val, tower))
	min_heap.sort(key=lambda x: x[1])
	for i in range(1, len(min_heap)):
		if min_heap[i][0] - min_heap[i - 1][0] > x:
			return print('NO')
	print('YES')
	print(*res)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solution()
main()


t = int(input())
for i in range(t):
	(n, m, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = [0 for j in range(n)]
	ind = []
	for i in range(n):
		ind.append([i, arr[i]])
	ind.sort(key=lambda x: x[1])
	print('YES')
	for i in range(n):
		if (i + 1) % m == 0:
			ans[ind[i][0]] = m
		else:
			ans[ind[i][0]] = (i + 1) % m
	print(*ans)


import sys
from sys import stdin
import math

def iinput():
	return int(input())

def minput():
	return map(int, input().split())

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

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

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

def flinput():
	return list(map(int, stdin.readline().strip().split()))
import heapq
for _ in range(iinput()):
	(n, m, x) = minput()
	list1 = linput()
	ll = []
	list2 = []
	for i in range(m):
		heapq.heappush(ll, (0, i + 1))
	for i in range(n):
		ans = heapq.heappop(ll)
		list2.append(ans[1])
		heapq.heappush(ll, (ans[0] + list1[i], ans[1]))
	print('YES')
	print(*list2)


for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	q = list(map(int, input().split()))
	q = [(q[i], i) for i in range(n)]
	q.sort()
	ans = [None] * n
	for i in range(n):
		ans[q[i][1]] = i % m
	print('YES')
	for i in ans:
		print(i + 1, end=' ')
	print()


t = int(input())
for i in range(t):
	a = [int(x) for x in input().split()]
	n = a[0]
	m = a[1]
	x = a[2]
	a = [int(x) for x in input().split()]
	bl = []
	for ind in range(len(a)):
		bl.append((a[ind], ind))
	bl.sort()
	to = []
	for ind in range(len(bl)):
		eff = ind % m
		if len(to) - 1 < eff:
			to.append([bl[ind]])
		else:
			to[eff].append(bl[ind])
	su = []
	res = [-1 for x in range(n)]
	ind = 1
	for el in to:
		summ = 0
		for k in el:
			summ += k[0]
			res[k[1]] = str(ind)
		su.append(summ)
		ind += 1
	minn = min(su)
	maxx = max(su)
	if maxx - minn > x:
		print('NO')
	else:
		print('YES')
		print(' '.join(res))


import heapq
cases = int(input())
while cases:
	cases -= 1
	(n, m, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = []
	towers = [(0, i) for i in range(1, m + 1)]
	heapq.heapify(towers)
	for (ind, num) in enumerate(arr):
		(h, i) = heapq.heappop(towers)
		ans.append(i)
		heapq.heappush(towers, (num + h, i))
	print('YES')
	print(*ans)


from math import ceil
import sys
from collections import defaultdict

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


from io import BytesIO, IOBase
from math import sqrt
import sys, os, math
from os import path
int_inpl = lambda : list(map(int, input().split()))
int_inpm = lambda : map(int, input().split())
int_inp = lambda : int(input())
inp = lambda : input()
from collections import Counter
import heapq
testcases = int_inp()
while testcases:
	testcases -= 1
	(n, m, int_var1) = int_inpm()
	int_arr = int_inpl()
	(arr, int_final_Sol) = ([], [0] * n)
	(int_var2, int_var4) = (float('-inf'), float('inf'))
	for int_init in range(n):
		arr.append([int_arr[int_init], int_init])
	int_stack = []
	heapq.heapify(int_stack)
	for int_init in range(m):
		heapq.heappush(int_stack, [0, int_init + 1])
	for int_init in reversed(range(n)):
		int_pp = heapq.heappop(int_stack)
		int_final_Sol[arr[int_init][1]] = int_pp[1]
		int_pp[0] += arr[int_init][0]
		heapq.heappush(int_stack, int_pp)
	for int_init in range(m):
		int_pp = heapq.heappop(int_stack)
		int_var2 = max(int_var2, int_pp[0])
		int_var4 = min(int_var4, int_pp[0])
	if int_var2 - int_var4 <= int_var1:
		print('YES')
		print(*int_final_Sol)
	else:
		print('NO')


for u in range(int(input())):
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	ans = [0] * n
	y = [[h[i], i] for i in range(n)]
	y = sorted(y)
	print('YES')
	for i in range(n):
		ans[y[i][1]] = i % m + 1
	print(*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
sqr = set()
for i in range(10002):
	sqr.add(2 * i * i)
	sqr.add(4 * i * i)
for _ in range(iinp()):
	(n, m, xx) = mp()
	hh = lmp()
	h = [(hh[i], i) for i in range(n)]
	h.sort(key=lambda x: -x[0])
	ans = l1d(n, -1)
	t = [[0, i + 1] for i in range(m)]
	heapify(t)
	for i in range(n):
		x = heappop(t)
		x[0] += h[i][0]
		ans[h[i][1]] = x[1]
		heappush(t, x)
	if max(t)[0] - min(t)[0] > xx:
		print('NO')
	else:
		print('YES')
		print(*ans)


import sys, collections, bisect, random, functools, math, heapq
import os
from io import BytesIO, IOBase
from types import GeneratorType
sys.setrecursionlimit(200000)
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))
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m, x) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	for i in range(n):
		arr[i] = [arr[i], i]
	arr.sort()
	hq = [[0, i] for i in range(1, m + 1)]
	heapq.heapify(hq)
	ans = [-1] * n
	while arr:
		(y, i) = arr.pop()
		(c, ind) = heapq.heappop(hq)
		ans[i] = ind
		heapq.heappush(hq, [c + y, ind])
	if max(hq, key=lambda a: a[0])[0] - min(hq, key=lambda a: a[0])[0] > x:
		print('NO')
	else:
		print('YES')
		print(' '.join((str(i) for i in ans)))


from sys import stdin, stdout
from math import *
from heapq import *

class hheap:

	def __init__(self, m):
		self.heap = []
		for i in range(1, m + 1):
			heappush(self.heap, (0, i))

	def add(self, hx):
		(s, id) = heappop(self.heap)
		s = s + hx
		heappush(self.heap, (s, id))
		return id

def main():
	(n, m, x) = [int(z) for z in stdin.readline().strip().split()]
	h = [int(z) for z in stdin.readline().strip().split()]
	y = []
	blocks = hheap(m)
	for x in h:
		y.append(str(blocks.add(x)))
	stdout.write('YES\n%s\n' % ' '.join(y))
	return 0
ntest = int(stdin.readline())
for i in range(ntest):
	main()


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

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

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

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

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

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

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj

def sieve():
	li = [True] * (10 ** 3 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	(prime, cur) = ([0] * 200, 0)
	for i in range(10 ** 3 + 5):
		if li[i] == True:
			prime[cur] = i
			cur += 1
	return prime

def SPF():
	mx = 10 ** 7 + 1
	spf = [mx] * mx
	spf[1] = 1
	for i in range(2, mx):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx, i):
				if i < spf[j]:
					spf[j] = i
	return spf

def prime(n, d):
	while n != 1:
		d[spf[n]] = d.get(spf[n], 0) + 1
		n = n // spf[n]
	return
mod = 1000000007
inf = 1e+18

def solve():
	(n, m, x) = L()
	h = L()
	li = []
	for i in range(n):
		li.append([h[i], i])
	li.sort(key=lambda x: x[0])
	each = n // m
	last = n // m + n % m
	tower = [0 for i in range(n)]
	cnt = 0
	tw = 1
	for i in range(n):
		if cnt == m:
			tw = 1
			cnt = 0
		tower[li[i][1]] = tw
		tw += 1
		cnt += 1
	print('YES')
	print(*tower)
	return
t = II()
for i in range(t):
	solve()


for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	h = [(h[i], i) for i in range(n)]
	h.sort(reverse=True)
	tow = [0] * m
	rev = False
	cur = 0
	ans = [0] * n
	for (hi, i) in h:
		tow[cur] += hi
		ans[i] = cur + 1
		if cur == 0 and rev:
			rev = False
		elif cur == m - 1 and (not rev):
			rev = True
		elif rev:
			cur -= 1
		else:
			cur += 1
	if max(tow) - min(tow) > x:
		print('NO')
	else:
		print('YES')
		print(*ans)


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left, bisect
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	x = dc(list)
	for i in range(n):
		x[l[i]].append(i)
	q = 0
	t = sorted(list(x.keys()))
	a = [-1] * n
	y = dc(int)
	m_max = 0
	m_min = sys.maxsize
	for i in t:
		for j in x[i]:
			a[j] = q % m + 1
			y[q % m + 1] += i
			q += 1
	c = 0
	for i in y:
		m_max = max(m_max, y[i])
		m_min = min(m_min, y[i])
		c += 1
	if c < m:
		print('NO')
	elif m_max - m_min <= k:
		print('YES')
		print(*a)
	else:
		print('NO')


from collections import defaultdict, Counter
from bisect import bisect, bisect_left
from math import sqrt, gcd

def read():
	return list(map(int, input().strip().split()))
ans_ = []

def f(arr, x):
	for i in range(1, len(arr)):
		if abs(arr[i - 1] - arr[i]) > x:
			return False
	return True
for _ in range(int(input())):
	(n, m, x) = read()
	arr = read()
	arr = [[arr[i], i] for i in range(n)]
	arr.sort()
	ans = [0] * n
	towers = [0] * m
	mx = 0
	while arr:
		for i in range(m):
			if not arr:
				break
			if towers[i] <= mx:
				(curr, idx) = arr.pop()
				towers[i] += curr
				ans[idx] = i + 1
				mx = max(mx, towers[i])
	if f(towers, x):
		ans_.append('YES')
		ans_.append(' '.join(map(str, ans)))
	else:
		ans_.append('NO')
for i in ans_:
	print(i)


from math import ceil

def answer():
	value = [0] * m
	ans = [-1] * n
	ind = 0
	for i in range(n):
		ans[x[i][1]] = ind + 1
		value[ind] += x[i][0]
		ind = (ind + 1) % m
	for i in range(m - 1):
		if abs(value[i] - value[i + 1]) > y:
			print('NO')
			return
	print('YES')
	print(*ans)
for T in range(int(input())):
	(n, m, y) = map(int, input().split())
	a = list(map(int, input().split()))
	x = [[a[i], i] for i in range(n)]
	x.sort(key=lambda x: x[0], reverse=True)
	answer()


import heapq

def solve(H, n, m, x):
	result = [0] * n
	pq = [(0, i + 1) for i in range(m)]
	heapq.heapify(pq)
	for i in range(n):
		(th, ti) = heapq.heappop(pq)
		th += H[i]
		result[i] = ti
		heapq.heappush(pq, (th, ti))
	return (True, result)
t = int(input())
for tc in range(t):
	(n, m, x) = map(int, input().split())
	H = list(map(int, input().split()))
	result = solve(H, n, m, x)
	if result is not False:
		print('YES')
		print(*result[1])
	else:
		print('NO')


from sys import stdin, stderr
input = stdin.readline

def dbp(*args, **kwargs):
	pass

def get_int_list():
	return [int(x) for x in input().strip().split()]
from heapq import heapify, heappop, heappush

def do_thing():
	(n, m, x) = get_int_list()
	hlist = get_int_list()
	towers = [(0, idx) for idx in range(m)]
	whichm = []
	for h in hlist:
		(th, ti) = heappop(towers)
		heappush(towers, (th + h, ti))
		whichm.append(ti)
	dbp(hlist)
	dbp(x, towers)
	return 'YES\n' + ' '.join((str(x + 1) for x in whichm))

def multicase():
	maxcc = int(input().strip())
	for cc in range(maxcc):
		print(do_thing())
multicase()


import os, sys, math
from io import BytesIO, IOBase
ma = lambda : map(int, input().split(' '))

def main():
	for _ in range(int(input())):
		(n, m, x) = ma()
		h = list(ma())
		hl = []
		for i in range(n):
			hl.append([h[i], i + 1])
		hl.sort()
		f = True
		a = [0] * m
		index = [0] * n
		for i in range(n):
			a[i % m] += hl[i][0]
			index[hl[i][1] - 1] = i % m + 1
		if max(a) - min(a) <= x:
			f = False
		if f:
			print('NO')
			continue
		print('YES')
		print(*index)
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout

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

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

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

def writeLine(s):
	stdout.write(str(s) + '\n')
	return

def main():
	t = readInt()
	for _ in range(t):
		(n, m, x) = readInts()
		h = list(readInts())
		si = sorted(range(len(h)), key=lambda k: h[k])
		output = [0] * n
		for i in range(len(si)):
			output[si[i]] = i % m + 1
		writeLine('YES')
		writeLine(' '.join(map(str, output)))
main()


import heapq

def question3():
	(N, M, X) = map(int, input().split())
	arr = list(map(int, input().split()))
	print('YES')
	k1 = []
	for i in range(1, M + 1):
		k1.append([0, i])
	heapq.heapify(k1)
	for i in range(N):
		read = heapq.heappop(k1)
		read[0] += arr[i]
		print(read[1], end=' ')
		heapq.heappush(k1, read)
remained_test_cases = int(input())
while remained_test_cases > 0:
	question3()
	print()
	remained_test_cases -= 1


from collections import defaultdict
from bisect import insort
for _ in range(int(input())):
	(N, M, X) = map(int, input().split())
	blocks_heights = map(int, input().split())
	if N < M:
		print('NO')
		continue
	print('YES')
	towers = defaultdict(list)
	smallest_height = 0
	heights = []
	smallest_towers = towers[0] = list(range(1, M + 1))
	blocks_positions = []
	for block_height in blocks_heights:
		smallest_tower_index = smallest_towers.pop()
		blocks_positions.append(smallest_tower_index)
		new_tower_height = smallest_height + block_height
		if new_tower_height not in towers:
			insort(heights, -new_tower_height)
		towers[new_tower_height] = towers_indices = towers[new_tower_height]
		towers_indices.append(smallest_tower_index)
		if not smallest_towers:
			smallest_height = -heights.pop()
			smallest_towers = towers[smallest_height]
	print(*blocks_positions)


for _ in range(int(input())):
	(n, m, x) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	print('YES')
	(a, an, p) = ([], [0] * n, 0)
	for i in range(n):
		a.append([l[i], i])
	a.sort()
	for i in range(n):
		an[a[i][1]] = p + 1
		p = (p + 1) % m
	print(*an)


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	o = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append((o[i], i))
	l.sort(reverse=True)
	ans = [0] * m
	ind = [0] * n
	j = 0
	p = 0
	for i in l:
		if p == 0:
			ans[j] += i[0]
			ind[i[1]] = j + 1
			j = j + 1
		if p == 1:
			ans[j] += i[0]
			ind[i[1]] = j + 1
			j = j - 1
		if j == -1:
			p = 0
			j = 0
			continue
		if j == m:
			p = 1
			j = m - 1
	flag = 0
	mi = 10 ** 18
	ma = -1
	for i in ans:
		mi = min(i, mi)
		ma = max(i, ma)
	if abs(mi - ma) > x:
		print('NO')
		continue
	print('YES')
	print(*ind)


import math
from collections import Counter
from itertools import permutations, combinations
import fractions

def solve():
	(n, m, x) = [int(s) for s in input().split(' ')]
	a = [int(s) for s in input().split(' ')]
	h = []
	for i in range(n):
		h.append([a[i], i])
	h.sort(key=lambda x: x[0])
	ans = [0] * n
	tower = [0] * m
	flag = True
	while h:
		if flag:
			out = False
			for i in range(m):
				if not h:
					out = True
					break
				(lst, index) = h.pop()
				ans[index] = i + 1
			if out:
				break
			flag = False
		else:
			out = False
			for i in range(m - 1, -1, -1):
				if not h:
					out = True
					break
				(lst, index) = h.pop()
				ans[index] = i + 1
			if out:
				break
			flag = True
	if max(tower) - min(tower) > x:
		print('NO')
	else:
		print('YES')
		print(*ans)
t = int(input())
for _ in range(t):
	solve()


for i in range(int(input())):
	(n, m, x) = map(int, input().split())
	l = list(map(int, input().split()))
	pair = [[l[i], i] for i in range(n)]
	final = [-1] * n
	pair.sort()
	towers = [0] * m
	m1 = 0
	for j in range(n):
		if m1 == m:
			m1 = 0
		towers[m1] += pair[j][0]
		final[pair[j][1]] = m1
		m1 += 1
	if max(towers) - min(towers) <= x:
		print('YES')
		for k in final:
			print(k + 1, end=' ')
		print()
	else:
		print('NO')


from math import gcd
from collections import defaultdict as dd
import heapq
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, M, X) = RL()
	H = RL()
	towers = [(0, i) for i in range(1, M + 1)]
	res = []
	for h in H:
		(height, index) = heapq.heappop(towers)
		res += [index]
		heapq.heappush(towers, (height + h, index))
	print('YES')
	print(' '.join(map(str, res)))
T = R()
for t in range(T):
	solve()


import heapq
hpush = heapq.heappush
hpop = heapq.heappop
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = []
	p1 = [(0, i) for i in range(1, m + 1)]
	heapq.heapify(p1)
	for (ind, num) in enumerate(arr):
		(h, i) = hpop(p1)
		ans.append(i)
		hpush(p1, (num + h, i))
	print('YES')
	print(*ans)


R = lambda : map(int, input().split())
(t,) = R()
exec(t * "n,m,x=R();r=[0]*n;i=0\nfor _,j in sorted(zip(R(),range(n))):r[j]=i=i%m+1\nprint('YES',*r)\n")


import heapq
T = int(input())
for _ in range(T):
	(n, m, x) = [int(x) for x in input().split()]
	h = [int(x) for x in input().split()]
	result = []
	q = []
	for i in range(1, m + 1):
		heapq.heappush(q, (0, i))
	for el in h:
		t = heapq.heappop(q)
		result += [str(t[1])]
		heapq.heappush(q, (t[0] + el, t[1]))
	print('YES')
	print(' '.join(result))


from io import BytesIO, IOBase
import sys
import math
import os
from collections import defaultdict
from math import ceil
from bisect import bisect_left, bisect_left
from time import perf_counter
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 input():
	return sys.stdin.readline().rstrip('\r\n')

def mint():
	return map(int, input().split())

def mfloat():
	return map(float, input().split())

def solve():
	(n, m, x) = mint()
	(*a,) = mint()
	if m > n:
		print('NO')
		return
	print('YES')
	a = sorted(list(zip(a, range(n))), reverse=True)
	p = 0
	d = 1
	ans = [0] * n
	for i in range(n):
		ans[a[i][1]] = p + 1
		p += d
		if p == m:
			d = -1
			p = m - 1
		if p == -1:
			p = 0
			d = 1
	print(*ans)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


import sys
input = sys.stdin.readline
import heapq
t = int(input())
for _ in range(t):
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	hq = [(0, i) for i in range(m)]
	heapq.heapify(hq)
	ans = [0] * n
	for i in range(n):
		(p, idx) = heapq.heappop(hq)
		ans[i] = idx + 1
		heapq.heappush(hq, (p + h[i], idx))
	print('YES')
	print(*ans)


import sys
from heapq import heappop, heappush
t = int(input())
for ii in range(t):
	(n, m, x) = map(int, input().split())
	A = list(map(int, input().split()))
	AA = [[A[i], i] for i in range(n)]
	AA.sort(reverse=True)
	A = AA
	if m == 1:
		print('YES')
		print(*[1] * n)
		continue
	ANS = [-1] * n
	Q = []
	for i in range(m):
		heappush(Q, (A[i][0], i))
		ANS[A[i][1]] = i
	for i in range(m, n):
		(p, ind) = heappop(Q)
		heappush(Q, (p + A[i][0], ind))
		ANS[A[i][1]] = ind
	ng = 0
	(p, _) = heappop(Q)
	while len(Q) > 0:
		(q, _) = heappop(Q)
	if q - p > x:
		ng = 1
	print('NO' if ng == 1 else 'YES')
	if ng == 0:
		for i in range(n):
			ANS[i] += 1
		print(*ANS)


from collections import Counter
import collections
import heapq

def process(case, n, m, x, arr):
	h = [(0, i) for i in range(1, m + 1)]
	heapq.heapify(h)
	res = []
	for v in arr:
		(height, idx) = heapq.heappop(h)
		height += v
		res.append(idx)
		heapq.heappush(h, (height, idx))
	print('YES')
	print(*res)
tcs = int(input())
for tc in range(tcs):
	(n, m, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	process(tc + 1, n, m, x, arr)


import sys
input = sys.stdin.readline
from heapq import heappop, heappush
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	A = list(map(int, input().split()))
	hp = [(0, i) for i in range(m)]
	ans = []
	for a in A:
		(b, i) = heappop(hp)
		ans.append(i + 1)
		b += a
		heappush(hp, (b, i))
	print('YES')
	print(*ans)


T = int(input())
for ii in range(T):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	arr = []
	for i in range(n):
		arr.append([i, a[i]])
	arr = sorted(arr, key=lambda x: x[1])
	ar = [[] for i in range(m)]
	ans = [0] * n
	for i in range(n):
		ar[i % m].append(arr[i][1])
		ans[arr[i][0]] = i % m + 1
	maxx = -1
	minn = 1e+20
	l = 0
	for i in ar:
		if len(i) > 0:
			l += 1
		maxx = max(sum(i), maxx)
		minn = min(sum(i), minn)
	if maxx - minn > x or l < m:
		print('NO')
	else:
		print('YES')
		print(*ans)


import heapq
import sys
input = iter(sys.stdin.read().splitlines()).__next__

def solve():
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	towers = [(0, i + 1) for i in range(m)]
	y = []
	for h_i in h:
		(height, tower) = heapq.heappop(towers)
		y.append(tower)
		heapq.heappush(towers, (height + h_i, tower))
	return ' '.join(map(str, y))
t = int(input())
output = []
for _ in range(t):
	output.append('YES')
	output.append(solve())
print(*output, sep='\n')


import heapq
for i in range(int(input())):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	heap = []
	for j in range(m):
		heap.append((0, j))
	for j in range(n):
		c = heapq.heappop(heap)
		heapq.heappush(heap, (c[0] + a[j], c[1]))
		a[j] = c[1] + 1
	print('YES')
	print(*a)


import sys
input = sys.stdin.readline
from heapq import *

def main():
	(n, m, x) = map(int, input().split())
	hlst = list(map(int, input().split()))
	hq = [(0, i) for i in range(1, m + 1)]
	ans = [-1] * n
	print('YES')
	for (i, h) in enumerate(hlst):
		(t, j) = heappop(hq)
		t += h
		ans[i] = j
		heappush(hq, (t, j))
	print(*ans)
for _ in range(int(input())):
	main()


for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = [-1] * n
	h = []
	tower = [0] * n
	for i in range(n):
		h.append((a[i], i))
	h.sort()
	for i in range(n):
		tower[i % m] += h[i][0]
		ans[h[i][1]] = i % m + 1
	tower.sort()
	idx = -1
	for i in range(n):
		if tower[i] != 0:
			idx = i
			break
	if tower[i] - tower[idx] > x:
		print('NO')
	else:
		print('YES')
		for i in ans:
			print(i, end=' ')
		print('')


from bisect import insort
from array import array
for _ in range(int(input())):
	(N, M, X) = map(int, input().split())
	blocks_heights = map(int, input().split())
	if N < M:
		print('NO')
		continue
	print('YES')
	towers = {}
	smallest_height = 0
	heights = array('i')
	smallest_towers = towers[0] = array('i', range(1, M + 1))
	blocks_positions = []
	for block_height in blocks_heights:
		smallest_tower_index = smallest_towers.pop()
		blocks_positions.append(smallest_tower_index)
		new_tower_height = smallest_height + block_height
		if new_tower_height not in towers:
			insort(heights, -new_tower_height)
			towers[new_tower_height] = array('i', [smallest_tower_index])
		else:
			towers[new_tower_height].append(smallest_tower_index)
		if not smallest_towers:
			del towers[smallest_height]
			smallest_height = -heights.pop()
			smallest_towers = towers[smallest_height]
	print(*blocks_positions)


import sys
import os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
depth = 1000005
mod = 1000000007
lim = mod * mod
sys.setrecursionlimit(depth)
from math import inf, ceil, sqrt
from collections import defaultdict
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if n < m:
		print('NO')
		continue
	print('YES')
	d = [[a[i], i + 1] for i in range(n)]
	d.sort(key=lambda x: x[0], reverse=True)
	ans = [-1 for _ in range(n)]
	for i in range(n):
		ans[d[i][1] - 1] = i % m + 1
	print(*ans)


import io, os
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve_tc():
	(n, m, x) = map(int, input().split())
	s = list(map(int, input().split()))
	ans = [0 for i in range(n)]
	l = []
	for i in range(len(s)):
		l.append([s[i], i])
	l.sort(key=lambda val: val[0])
	a = 1
	for i in l:
		ans[i[1]] = a
		a += 1
		if a > m:
			a = 1
	return ans
t = int(input())
while t > 0:
	t -= 1
	m = solve_tc()
	print('YES')
	sys.stdout.write(' '.join(map(str, m)))
	sys.stdout.write('\n')


from sys import stdin
f = stdin
text = f.read().splitlines()
t = int(text[0])
import heapq
from queue import PriorityQueue

def solve(n, m, x, h):
	sortedh = sorted(enumerate(h), key=lambda x: -x[1])
	towers = [sortedh[i][1] for i in range(m)]
	towerinds = [[sortedh[i][0]] for i in range(m)]
	towerq = PriorityQueue()
	for i in range(m):
		towerq.put((sortedh[i][1], i))
	for i in range(m, n):
		current = towerq.get()
		towerq.put((current[0] + sortedh[i][1], current[1]))
		towerinds[current[1]].append(sortedh[i][0])
	inds = [0 for i in range(n)]
	for (ind, indt) in enumerate(towerinds):
		for j in indt:
			inds[j] = ind
	return (inds, towers)

def is_good(towers, x):
	return max(towers) - min(towers) <= x
for i in range(1, 2 * t + 1, 2):
	(n, m, x) = map(int, text[i].split())
	h = list(map(int, text[i + 1].split()))
	(res, towers) = solve(n, m, x, h)
	if is_good(towers, x):
		print('YES')
		print(' '.join(map(lambda x: str(x + 1), res)))
	else:
		print('NO')


import heapq
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = []
	for i in range(m):
		s.append((0, i + 1))
	ans = []
	heapq.heapify(s)
	for i in range(n):
		p = heapq.heappop(s)
		t = p[0] + l[i]
		ans.append(p[1])
		heapq.heappush(s, (t, p[1]))
	print('YES')
	print(*ans)


import heapq
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {i: 0 for i in range(n)}
	p = [[l[i], [i]] for i in range(n)]
	p.sort(reverse=True)
	q = []
	for i in range(m):
		q.append(p[i])
	heapq.heapify(q)
	for i in range(m, n):
		(ele, k) = heapq.heappop(q)
		ele = ele + p[i][0]
		k.append(p[i][1][0])
		heapq.heappush(q, [ele, k])
	if max(q)[0] - min(q)[0] > x:
		print('NO')
	else:
		print('YES')
		for i in range(m):
			(ele, k) = heapq.heappop(q)
			for j in k:
				d[j] = i + 1
		for i in range(n):
			print(d[i], end=' ')
		print()


for t in range(int(input())):
	(n, m, x) = map(int, input().split())
	lis = list(map(int, input().split()))
	mls = [(0, i) for i in range(m)]
	import heapq
	print('YES')
	for i in range(n):
		pop = heapq.heappop(mls)
		(mn, ind) = pop
		print(ind + 1, end=' ')
		mn += lis[i]
		heapq.heappush(mls, (mn, ind))
	print()


import sys, getpass
import math, random
import functools, itertools, collections, heapq, bisect
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
M9 = 10 ** 9 + 7
MAXINT = sys.maxsize
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]

def solve_(lst, num_towers, max_diff):
	lst = sorted([(x, i) for (i, x) in enumerate(lst)])[::-1]
	heights = [0 for _ in range(num_towers)]
	res = [-2 for _ in lst]
	for (j, (x, i)) in enumerate(lst[:num_towers]):
		heights[j] += x
		res[i] = j
	heights = [(h, j) for (j, h) in enumerate(heights)]
	heapq.heapify(heights)
	for (x, i) in lst[num_towers:]:
		(h, j) = heapq.heappop(heights)
		h += x
		res[i] = j
		heapq.heappush(heights, (h, j))
	return res
for case_num in range(int(input())):
	(_, num_towers, max_diff) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	res = solve(lst, num_towers, max_diff)
	res = [str(x + 1) for x in res]
	print('YES')
	print(' '.join(res))


T = int(input())
for _ in range(T):
	(n, m, x) = map(int, input().split())
	a1 = list(map(int, input().split()))
	a = []
	for i in range(n):
		a.append([a1[i], i])
	a.sort()
	print('YES')
	ans = []
	weights = []
	for i in range(m):
		weights.append([0, i])
		ans.append([])
	i = 0
	while i + m < n:
		weights.sort(reverse=True)
		for j in range(i, i + m):
			ans[weights[j - i][1]].append(a[j][1])
			weights[j - i][0] += a[j][0]
		i += m
	weights.sort()
	for j in range(i, n):
		ans[weights[j - i][1]].append(a[j][1])
	final = [0] * n
	count = 0
	for i in ans:
		count += 1
		for j in i:
			final[j] = count
	print(*final)


import string
from collections import deque, defaultdict
import heapq
DEBUG = 0

def main():
	T = Input.read_typed(int)[0]
	while T:
		(n, m, x) = Input.read_typed(int)
		h = Input.read_typed(int)
		ans = [-1 for _ in range(n)]
		t_heap = Heap(data=[(0, idx + 1) for idx in range(m)])
		h_heap = Heap(data=[(h, idx) for (idx, h) in enumerate(h)], key=lambda item: -item[0])
		while h_heap:
			(h, hid) = h_heap.pop()
			(t, tid) = t_heap.pop()
			t_heap.push((t + h, tid))
			ans[hid] = tid
		towers = []
		while t_heap:
			towers.append(t_heap.pop()[0])
		if towers[-1] - towers[0] <= x:
			print('YES')
			print(' '.join(map(str, ans)))
		else:
			print('NO')
		T -= 1

class Input:

	def __init__(self):
		pass

	@staticmethod
	def read_typed(cls):
		return list(map(cls, input().split()))

	@staticmethod
	def read():
		return input()

class Debug:

	def __init__(self):
		import sys
		sys.stdout = open('output.out', 'w')
		sys.stdin = open('input.in', 'r')

	def __delete__(self):
		sys.stdout.close()
		sys.stdin.close()

class Heap:

	def __init__(self, data=[], key=None):
		self.key = key or (lambda x: x)
		self.idx = 0
		self.key_idx_heap = []
		self.data = {}
		for datum in data:
			self.push(datum)

	def push(self, value):
		self.idx += 1
		heapq.heappush(self.key_idx_heap, (self.key(value), self.idx))
		self.data[self.idx] = value

	def pop(self):
		(_, idx) = heapq.heappop(self.key_idx_heap)
		return self.data.pop(idx)

	def top(self):
		return self.data[self.key_idx_heap[0][1]]

	def __bool__(self):
		return bool(self.key_idx_heap)

	def __len__(self):
		return len(self.data)

def run():
	if DEBUG:
		_ = Debug()
	main()
run()


import sys
input = sys.stdin.buffer.readline
for t in range(int(input())):
	(N, M, X) = map(int, input().split())
	A = list(map(int, input().split()))
	B = [(A[i], i) for i in range(N)]
	B.sort()
	ANS = [0] * N
	for i in range(N):
		ANS[B[i][1]] = i % M + 1
	print('YES')
	print(*ANS)


for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	order = sorted(range(n), key=lambda i: -a[i])
	ans = [0] * n
	cur = 0
	for i in order:
		ans[i] = cur + 1
		cur = (cur + 1) % m
	print('YES')
	print(*ans)


R = lambda : list(map(int, input().split()))
(t,) = R()
for _ in range(t):
	(n, m, x) = R()
	h = R()
	h = [(h[i], i) for i in range(n)]
	h.sort()
	ans = [0] * n
	for i in range(n):
		ans[h[i][1]] = i % m + 1
	print('YES')
	print(*ans)


import sys
from collections import deque
from queue import PriorityQueue
from math import gcd
from math import log
from math import ceil
from math import pi
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
for _ in range(ii()):
	(n, m, x) = il()
	a = il()
	b = []
	ans = [0 for i in range(n)]
	c = [0 for i in range(m)]
	for i in range(n):
		b.append([a[i], i])
	b.sort()
	ind = 1
	for i in range(m):
		ans[b[n - m + i][1]] = ind
		c[ind - 1] += b[n - m + i][0]
		ind += 1
	ind = 1
	for i in range(n - m):
		ans[b[i][1]] = ind
		c[ind - 1] += b[i][0]
		ind += 1
		if ind > m:
			ind = 1
	if max(c) - min(c) > x:
		print('NO')
	else:
		print('YES')
		print(*ans)


import sys
import os
import math
from io import BytesIO, IOBase
from collections import defaultdict, Counter, deque
import heapq
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	l = []
	for j in range(m):
		l.append([0, j + 1])
	heapq.heapify(l)
	ind = [0] * n
	l1 = []
	for j in range(n):
		l1.append([a[j], j])
	l1.sort(reverse=True)
	for j in range(n):
		cur = heapq.heappop(l)
		cur[0] += l1[j][0]
		ind[l1[j][1]] = cur[1]
		heapq.heappush(l, cur)
	mi = l[0][0]
	ma = 0
	for j in l:
		ma = max(ma, j[0])
	if ma - mi > x:
		print('NO')
	else:
		print('YES')
		print(*ind)


from typing import List
from heapq import heappop, heappush

def solve(n: int, m: int, x: int, h: List[int]) -> None:
	h = sorted(([h[i], i] for i in range(n)))
	h.sort()
	ans = [0] * n
	heap = []
	for i in range(1, m + 1):
		heappush(heap, [0, i])
	for i in range(n - 1, -1, -1):
		(val, ind) = h[i]
		node = heappop(heap)
		node[0] += val
		ans[ind] = node[1]
		heappush(heap, node)
	if max(heap)[0] - min(heap)[0] > x:
		print('NO')
		return
	ans_str = ''
	for x in ans:
		ans_str += str(x) + ' '
	print('YES')
	print(ans_str)
	return
test_cases = int(input())
for _ in range(test_cases):
	(n, m, x) = list(map(int, input().split()))
	h = list(map(int, input().split()))
	solve(n, m, x, h)


import heapq
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = []
	tower = [(0, i) for i in range(1, m + 1)]
	for i in arr:
		(stack, idx) = heapq.heappop(tower)
		ans.append(idx)
		heapq.heappush(tower, (stack + i, idx))
	print('YES')
	print(*ans)


for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	new = []
	for i in range(n):
		new.append([arr[i], i])
	new.sort(reverse=True)
	res = [0] * n
	for i in range(0, n, 2 * m):
		c = 0
		while i + c < n and c < m:
			res[new[i + c][1]] = c + 1
			c += 1
	for i in range(m, n, 2 * m):
		c = 0
		while i + c < n and c < m:
			res[new[i + c][1]] = m - c
			c += 1
	print('YES')
	print(*res)


from heapq import *

def f(a, m, x):
	l = [(0, i) for i in range(m)]
	heapify(l)
	ans = [None] * len(a)
	for i in range(len(a)):
		t = list(heappop(l))
		t[0] += a[i]
		ans[i] = t[1] + 1
		heappush(l, tuple(t))
	mn = min(l, key=lambda s: s[0])[0]
	mx = max(l, key=lambda s: s[0])[0]
	if mx - mn <= x:
		print('YES')
		print(*ans)
		return
	print('NO')
for _ in range(int(input())):
	(n, m, x) = map(int, input().strip().split())
	l = list(map(int, input().strip().split()))
	f(l, m, x)


from heapq import heappush, heappop

def putin():
	return map(int, input().split())

def sol():
	(n, m, x) = putin()
	A = list(putin())
	H = []
	if n < m:
		print('NO')
		return
	print('YES')
	for i in range(m):
		heappush(H, (0, i + 1))
	for elem in A:
		(a, b) = heappop(H)
		print(b, end=' ')
		heappush(H, (a + elem, b))
	print()
for iter in range(int(input())):
	sol()


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

def solution():
	(n, m, x) = mapit()
	arr = mapit()
	res = [0] * n
	heap = [(0, i + 1) for i in range(m)]
	for i in range(n):
		(tow, idx) = heapq.heappop(heap)
		tow += arr[i]
		res[i] = idx
		heapq.heappush(heap, (tow, idx))
	print('YES')
	print(*res)
	return
t = int(input())
while t:
	t -= 1
	solution()


g = int(input())
import heapq
while g > 0:
	g -= 1
	print('YES')
	(n, m, x) = map(int, input().split())
	a = list(map(int, input().split()))
	pq = []
	for i in range(m):
		heapq.heappush(pq, (0, i))
	for i in a:
		mi = heapq.heappop(pq)
		print(mi[1] + 1)
		heapq.heappush(pq, (mi[0] + i, mi[1]))


def task():
	(n, m, x) = [int(x) for x in input().split()]
	s = [int(x) for x in input().split()]
	d = sorted(range(n), key=lambda t: s[t])
	ans = [0] * n
	print('YES')
	a = 0
	for i in d:
		ans[i] = a + 1
		a = (a + 1) % m
	print(' '.join([str(x) for x in ans]))
for _ in range(int(input())):
	task()


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
from heapq import *
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, m, x) = mp()
	ans = [0 for i in range(n)]
	l = li()
	p = [[l[i], i] for i in range(n)]
	p.sort(reverse=True)
	h = []
	dp = [0 for i in range(m)]
	for i in range(m):
		ans[p[i][1]] = i + 1
		heappush(h, (p[i][0], i + 1))
		dp[i] += p[i][0]
	for i in range(m, n):
		(a, b) = heappop(h)
		dp[b - 1] += p[i][0]
		ans[p[i][1]] = b
		heappush(h, (a + p[i][0], b))
	if max(dp) - min(dp) <= x:
		pr('YES')
		print(*ans)
		return
	pr('NO')
for _ in range(inp()):
	solve()


import heapq
for _ in range(int(input())):
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	tower = [[0, i] for i in range(m)]
	heapq.heapify(tower)
	res = [0] * n
	for j in range(n):
		(height, idx) = heapq.heappop(tower)
		height += h[j]
		res[j] = idx + 1
		heapq.heappush(tower, [height, idx])
	if abs(tower[0][0] - tower[-1][0]) <= x:
		print('YES')
		print(*res)
	else:
		print('NO')


import sys
import math
import random
input = sys.stdin.readline

def pow(a, n, m):
	if n == 0:
		return 1
	x = pow(a, n // 2, m)
	if n % 2 == 0:
		return x * x % m
	else:
		return x * x * a % m
t = int(input())
while t > 0:
	(n, m, x) = map(int, input().split())
	h = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append((h[i], i))
	ans = [0 for i in range(n)]
	su = []
	for i in range(m):
		su.append([0, i + 1])
	l.sort()
	k = n % m
	j = 0
	for i in range(k, n):
		ans[l[i][1]] = j + 1
		su[j][0] += l[i][0]
		j = (j + 1) % m
	su.sort()
	for i in range(k):
		ans[l[i][1]] = su[k - i - 1][1]
		su[k - i - 1][0] += l[i][0]
	su.sort()
	if su[-1][0] - su[0][0] > x:
		print('NO')
	else:
		print('YES')
		for i in ans[:-1]:
			print(i, end=' ')
		print(ans[-1])
	t -= 1


for _ in range(int(input())):
	print('YES')
	(n, h, k) = map(int, input().split())
	s = map(int, input().split())
	ar = [[] for i in range(h)]
	dc = sorted(enumerate(s), key=lambda x: (x[1], x[0]), reverse=True)
	x = 0
	c = 0
	while c < n:
		if x % 2 == 0:
			for i in range(h):
				ar[i].append(dc[c][0])
				c += 1
				if c == n:
					break
		else:
			for i in range(h - 1, -1, -1):
				ar[i].append(dc[c][0])
				c += 1
				if c == n:
					break
		x += 1
	l = [0 for i in range(n)]
	for i in range(h):
		for j in range(len(ar[i])):
			l[ar[i][j]] = i + 1
	print(*l)