#include <bits/stdc++.h>
using namespace std;
struct item {
  int nr, index, color = 0;
};
bool sort_by_nr(const item &A, const item &B) { return A.nr < B.nr; }
bool sort_by_index(const item &A, const item &B) { return A.index < B.index; }
void solve() {
  int n, k;
  cin >> n >> k;
  vector<item> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].nr;
    v[i].index = i;
  }
  map<int, int> nr_occur;
  for (auto &it : v) nr_occur[it.nr]++;
  int max_score = 0;
  for (auto &it : nr_occur) max_score += min(k, it.second);
  max_score = max_score / k;
  sort(v.begin(), v.end(), sort_by_nr);
  int current_color = 1;
  map<int, int> color_paints;
  map<int, int> nr_used;
  for (auto &it : v) {
    if (color_paints[current_color] == max_score) break;
    if (nr_used[it.nr] == k) continue;
    it.color = current_color;
    nr_used[it.nr]++;
    color_paints[current_color]++;
    current_color += 1;
    if (current_color == (k + 1)) current_color = 1;
  }
  sort(v.begin(), v.end(), sort_by_index);
  for (auto &it : v) cout << it.color << " ";
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) solve();
}
