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

 void hota(){
 	int n,m,x;
 	cin>>n>>m>>x;
 	vector<pair<int,int>> v;
 	for (int i = 0; i < n; ++i)
 	{
 		int x;
 		cin>>x;
 		v.push_back(make_pair(x,i+1));
 	}
 	sort(v.begin(), v.end());
 	std::vector<int> ans(m,0);
 	vector<pair<int,int>> r;
 	int j=0;
 	while(j<n)
 	{
 		int i =0;
 		while(i<m && j<n)
 		{
 			ans[i]+=v[j].first;
 			r.push_back(make_pair(v[j].second,i+1));
 			i++;
 			j++;
 		}
 	}
 	int mx = *max_element(ans.begin(), ans.end());
 	int mn = *min_element(ans.begin(), ans.end());
 	if(mx-mn>x || mn == 0)
 		{cout<<"NO"<<endl;}
 	else
 	{
 		sort(r.begin(), r.end());
 		cout<<"YES"<<endl;
 		for (int i = 0; i < n; ++i)
 		{
 			cout<<r[i].second<<" ";
 		}
 		cout<<endl;
 	}
 }

 signed main(){
 	std::ios::sync_with_stdio(false);
 	cin.tie(NULL);
 	int t;
 	cin>>t;
 	for(int tc=1;tc<=t;tc++){
 	
 		hota();
 	}
 }