#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define pii pair<ll, ll>
#define vp vector<pii>
#define vs vector<string>
#define mii map<int, int>
void show(vi a){for(int i=0;i<a.size();i++){cout<<a[i]<<" ";}cout<<endl;}

void show(priority_queue <pii, vector<pii>, greater<pii>> pq){
	while(!pq.empty()){
		cout<<pq.top().first<<", ";
		pq.pop();
	}
}
int main(){
  ios_base::sync_with_stdio(false);
  int t; cin>>t;
  while(t--){
  	int n, m, x;
	  priority_queue <pii, vector<pii>, greater<pii>> pq;

	  cin>>n>>m>>x;
	  vp a(n); for(int i = 0; i < n; i++) cin>>a[i].first, a[i].second = i;
	  sort(a.begin(), a.end());
	  for(int i = 1; i <= m; i++) pq.push(pii(0, i));

	  int i = 0;
	  mii table;
	  while(i < n){
	  	pii getVal = pq.top();
	  	pq.pop();
	  	pq.push(pii(getVal.first+a[i].first, getVal.second));
	  	table[a[i].second] = getVal.second;
	  	i++;
	  }
	  vi ans;
	  while(!pq.empty()){
	  	ans.push_back(pq.top().first);
	  	pq.pop();
	  }
	  sort(ans.begin(), ans.end());
	  if(ans[ans.size()-1] - ans[0] > x){
	  	cout<<"NO"<<endl;
	  }else{
	  	cout<<"YES"<<endl;
	  	for(int i = 0; i < a.size(); i++){
	  		cout<<table[i]<<" ";
	  	}
	  	cout<<endl;
	  }


  }
    
	
  

}
