#include <bits/stdc++.h>
using namespace std;
long long ceildiv(long long one, long long two) {
  if (one % two == 0) {
    return one / two;
  } else {
    return one / two + 1;
  }
}
long long power(long long n, long long pow, long long m) {
  if (pow == 0) return 1;
  if (pow % 2 == 0) {
    long long x = power(n, pow / 2, m);
    return (x * x) % m;
  } else
    return (power(n, pow - 1, m) * n) % m;
}
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long factorial(long long n, long long mod) {
  if (n > 1)
    return (n * factorial(n - 1, mod)) % mod;
  else
    return 1;
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
vector<long long> read(long long n) {
  vector<long long> a;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a.push_back(x);
  }
  return a;
}
vector<vector<pair<long long, long long>>> adj;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a = read(n);
  vector<long long> rep = a;
  sort(a.begin(), a.end());
  vector<vector<long long>> colors(k);
  queue<long long> q;
  for (long long i = 0; i < k; i++) {
    q.push(i);
  }
  for (long long i = 0; i < n; i++) {
    long long ind = q.front();
    long long x = upper_bound(colors[ind].begin(), colors[ind].end(), a[i]) -
                  lower_bound(colors[ind].begin(), colors[ind].end(), a[i]);
    if (x == 0) {
      colors[ind].push_back(a[i]);
      q.pop();
      q.push(ind);
    } else {
      continue;
    }
  }
  long long len = 1000000000;
  for (long long i = 0; i < k; i++) {
    len = min(len, (long long)colors[i].size());
  }
  for (long long i = 0; i < k; i++) {
    while (colors[i].size() > len) {
      colors[i].pop_back();
    }
  }
  map<long long, vector<long long>> mp;
  for (long long i = 0; i < k; i++) {
    for (auto x : colors[i]) {
      mp[x].push_back(i + 1);
    }
  }
  for (long long i = 0; i < n; i++) {
    if (mp[rep[i]].size() == 0) {
      cout << 0 << " ";
    } else {
      cout << mp[rep[i]].back() << " ";
      mp[rep[i]].pop_back();
    }
  }
  cout << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ;
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
