#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 2e5 + 9;
int t, n, k, a[N];
vector<int> v[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
      v[i].clear();
      a[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      v[x].push_back(i);
    }
    int d = 0;
    for (int i = 1; i <= n; i++) {
      while (v[i].size() > k) v[i].pop_back();
      d = (d + (int)v[i].size()) % k;
    }
    for (int i = 1; i <= n; i++)
      while (d > 0 && !v[i].empty()) v[i].pop_back(), d--;
    int cur = 1;
    for (int i = 1; i <= n; i++) {
      for (auto j : v[i]) {
        a[j] = cur++;
        if (cur > k) cur = 1;
      }
    }
    for (int i = 1; i <= n; i++) cout << a[i] << " ";
    cout << "\n";
  }
}
