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

ll h[100005];
int id[100005];
int ans[100005];
ll th[100005];
void solve () {
    int n, m, x; cin >> n >> m >> x;
    priority_queue<pair<ll, int>> pq;
    for (int i = 1; i <= m; ++i) pq.push({(th[i] = 0), i});
    for (int i =1 ; i <= n; ++i) {
        cin >> h[i];
        id[i] = i;
    }
    sort(id+1, id+1+n, [] (int lhs, int rhs) {
        return h[lhs] < h[rhs];
    });
    for (int j = 1; j <= n; ++j) {
        int i = id[j];
        auto t = pq.top(); pq.pop();
        ans[i] = t.second;
        th[t.second] = th[t.second]+h[i];
        pq.push({-th[t.second], t.second});
    }
    if (*max_element(th + 1, th + 1 + m) - *min_element(th+1,th+1+m) > x) {
        cout << "NO" << endl;
        return;
    }
    cout << "YES" << endl;
    for (int i = 1; i <= n; ++i) cout << ans[i] << ' ';
    cout << endl;
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int t; cin >> t;
    while (t--) {
        solve();
    }
}