#include <bits/stdc++.h>
using namespace std;
void func() {
  int n, k, tot = 0;
  cin >> n >> k;
  unordered_map<long long, vector<long long>> m;
  unordered_map<long long, long long> mc;
  long long a[n], ans[n];
  fill(ans, ans + n, -1);
  m.clear();
  mc.clear();
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]].push_back(i);
  }
  for (auto &pr : m) {
    if (pr.second.size() <= k)
      tot += pr.second.size();
    else
      tot += k;
  }
  for (int i = 0; i < k; i++) {
    mc[i + 1] = tot / k;
  }
  long long index = 1;
  long long temp;
  for (auto &pr : m) {
    if (pr.second.size() > k) {
      for (int i = 0; i < k; i++) {
        temp = 0;
        while (mc[index] == 0) {
          index++;
          temp++;
          if (index > k) index = 1;
          if (temp == k) break;
        }
        if (temp == k) break;
        ans[pr.second[i]] = index;
        mc[index]--;
        index++;
        if (index > k) index = 1;
      }
    } else {
      for (int i = 0; i < pr.second.size(); i++) {
        temp = 0;
        while (mc[index] == 0) {
          index++;
          temp++;
          if (index > k) index = 1;
          if (temp == k) break;
        }
        if (temp == k) break;
        ans[pr.second[i]] = index;
        mc[index]--;
        index++;
        if (index > k) index = 1;
      }
    }
    if (temp == k) break;
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] == -1) ans[i] = 0;
    cout << ans[i] << " ";
  }
  cout << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    func();
  }
}
