#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define pb push_back
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t = 1; 
	cin >> t; 

	while(t--) {
		ll n, m, x;
		cin >> n >> m >> x;

		vector<ll> h(n);
		vector<ll> ans(n);
		multiset<pair<ll, ll>> M;
		for (int i = 0; i < m; ++i) M.insert({0, i + 1});
		bool ok = 1;
		for (int i = 0; i < n; ++i) {
			cin >> h[i];
			auto it = M.begin();
			pair<ll, ll> p = make_pair(it -> first + h[i], it -> second);
			ans[i] = it -> second;
			M.erase(it);
			M.insert(p);

			auto st = M.begin(), end = prev(M.end());

			if (end -> first - st -> first > x) {
				ok = 0;
			}
		}
		if (!ok) {
			cout << "NO\n";
			continue;
		}
		cout << "YES\n";
		for (auto x: ans)
			cout << x << " ";
		cout << "\n";
	}
	
	return 0;
}