#include <bits/stdc++.h>
using namespace std;
template <class Num>
Num mabs(Num x) {
  if (x < 0) return -x;
  return x;
}
void solve() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> a(n);
  vector<int> cnt(n + 1, 0);
  set<pair<int, int>> ss;
  vector<vector<int>> gdje(n + 1, vector<int>());
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
    gdje[a[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (cnt[i] > 0) ss.insert({-cnt[i], i});
  }
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    sum += min(k, cnt[i]);
  }
  int svaki = sum / k;
  vector<int> sol(n, 0);
  for (int i = 1; i <= k; i++) {
    int cc = 0;
    vector<int> out;
    while (svaki > cc) {
      pair<int, int> t = *ss.begin();
      ss.erase(ss.begin());
      cnt[t.second]--;
      int ind = gdje[t.second].back();
      gdje[t.second].pop_back();
      out.push_back(t.second);
      sol[ind] = i;
      cc++;
    }
    for (int p : out)
      if (cnt[p] > 0) ss.insert({-cnt[p], p});
  }
  for (int s : sol) printf("%d ", s);
  puts("");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
