#include <bits/stdc++.h>
using namespace std;
int const N = 1e9 + 7;
vector<long long> seive(1000000, 1);
vector<long long> primes;
void doSeive() {
  for (long long i = 2; i < 1000000; i++) {
    if (seive[i]) {
      primes.push_back(i);
      for (long long j = i * i; j < 1000000; j += i) {
        seive[j] = 0;
      }
    }
  }
}
long long nCr(long long n, long long r) {
  if (n < r) return 0;
  if (r > n - r) {
    r = n - r;
  }
  long long res = 1;
  for (long long i = 0; i < r; i++) {
    res *= n - i;
    res /= i + 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return (b % a, a);
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> adj[n + 1];
  vector<long long> col(n, 0);
  for (long long i = 0; i < n; i++) {
    long long no;
    cin >> no;
    adj[no].push_back(i);
  }
  vector<long long> vis(n + 1, 0);
  long long cnt = n;
  for (long long i = 1; i <= n; i++) {
    if (adj[i].size() >= k) {
      vis[i] = 1;
      cnt -= adj[i].size();
      for (int j = 0; j < k; j++) {
        col[adj[i][j]] = j + 1;
      }
    }
  }
  cnt -= (cnt % k);
  long long p = 0;
  for (long long i = 1; i <= n; i++) {
    if (vis[i] == 0 && adj[i].size() > 0) {
      for (int j = 0; j < adj[i].size() && cnt > 0; j++) {
        p++;
        if (p == k + 1) p = 1;
        col[adj[i][j]] = p;
        cnt--;
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    cout << col[i] << " ";
  }
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
