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

#define int int64_t
#define mod 1000000007

int32_t main() {

  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int t;
  cin >> t;
  while (t--) {
    int n, m, x;
    cin >> n >> m >> x;
    multiset<pair<int, int>> s;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    // sort(a.begin(), a.end());
    for (int i = 0; i < m; i++) {
      s.insert({0, i});
    }
    vector<int> ans(n);
    vector<int> towers(m);
    for (int i = 0; i < n; i++) {
      pair<int, int> p = *(s.begin());
      int index = p.second;
      int ht = p.first;
      s.erase(s.begin());
      s.insert({ht + a[i], index});
      ans[i] = index + 1;
      towers[index] += a[i];
    }
    int lo = INT_MAX, hi = INT_MIN;
    for (int i = 0; i < m; i++) {
      lo = min(towers[i], lo);
      hi = max(towers[i], hi);
    }
    if (hi - lo > x) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
    for (int i = 0; i < n; i++) {
      cout << ans[i] << ' ';
    }
    cout << endl;
  }

  return 0;
}