#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin >> t;
    while( t-- ){
        int n,m,x;
        cin >> n >> m >> x;
        //  N -> Boxes
        //  M -> Towers to be Made
        //  X -> Permissible height difference between any two towers
        vector<pair<int,int>> corr(0);
        for(int i=0;i<n;i++){
            long long int w;
            cin >> w;
            corr.push_back({w,i});
        }
        sort(corr.begin(),corr.end());
        int t_size = corr.size();
        int sitr = 0;
        vector<int> ans(n,0);
        vector<long long int> bl(m,0);
        while(t_size != 0){
            int block = 1;
            int check = corr.size();
            int j;
            for(j=sitr;j<min((sitr+m),check);j++){
                ans[corr[j].second] = block;
                bl[block-1] += corr[j].first;
                block++;
            }
            sitr = j;
            t_size -= min(t_size,m);
        }
        sort(bl.begin(),bl.end());
        if(abs(bl[0]-bl[bl.size()-1]) <= x){
            cout << "YES" << endl;
            for(int i=0;i<ans.size();i++){
                cout << ans[i] << " ";
            }
            cout << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
}