#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define f(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define mod 1000000007
#define op(x) cout << #x << "=" << x << "\n";
#define ps(x, y) fixed << setprecision(y) << x
#define inp(a, n)               \
    for (int i = 0; i < n; i++) \
        cin >> a[i];
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
int main()
{
#ifndef ONLINE_JUDGE
    freopen(".input.txt", "r", stdin);
    freopen(".output.txt", "w", stdout);
#endif
    FIO;
    int t = 1;
    cin >> t;
    while (t--)
    {
        ll n, m, x;
        cin >> n >> m >> x;
        priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> tow;
        for (int i = 0; i < m; i++)
        {
            tow.push({0, i + 1});
        }

        vector<pair<ll, ll>> v(n);

        for (int i = 0; i < n; i++)
        {
            cin >> v[i].ff;
            v[i].ss = i;
        }
        // for (auto i : v)
        // {
        //     cout << i.ff << " " << i.ss << endl;
        // }
        vector<ll> ans(n);
        sort(v.begin(), v.end());
        for (int i = n - 1; i >= 0; i--)
        {
            pair<ll, ll> val = tow.top();
            tow.pop();
            ans[v[i].ss] = val.ss;
            val.ff += v[i].ff;
            tow.push(val);
        }

        ll maxi = LONG_MIN, mini = LONG_MAX;

        for (int i = 0; i < m; i++)
        {
            pair<ll, ll> val = tow.top();
            tow.pop();
            maxi = max(maxi, val.ff);
            mini = min(mini, val.ff);
        }
        // op(maxi);
        // op(mini);
        if ((maxi - mini) <= x)
        {
            cout << "YES" << endl;
            for (int i = 0; i < n; i++)
                cout << ans[i] << " ";
            cout << endl;
            continue;
        }
        else
        {
            cout << "NO" << endl;
            continue;
            
        }
    }
    return 0;
}