#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p) {
  cerr << "{";
  _print(p.first);
  cerr << ",";
  _print(p.second);
  cerr << "}";
}
template <class T>
void _print(vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(set<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
  cerr << "[ ";
  for (auto i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V>
void _print(unordered_map<T, V> v) {
  cerr << "[ ";
  for (auto i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
bool by2(pair<long long, long long> &p1, pair<long long, long long> &p2) {
  return p1.second < p2.second;
}
long long power(long long a, long long n) {
  long long result = 1;
  while (n) {
    if (n & 1) result = (result * a) % 1000000007;
    n >>= 1;
    a = (a * a) % 1000000007;
  }
  return result;
}
void xagar() {
  int tc;
  cin >> tc;
  while (tc--) {
    long long n, k;
    cin >> n >> k;
    long long a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long ans[n];
    unordered_map<long long, vector<long long>> ump;
    unordered_map<long long, long long> cnt3;
    long long idx = 1, temp;
    for (int i = 0; i < n; i++) {
      ump[a[i]].push_back(i);
    }
    long long cnt1 = 0, cnt2 = 0;
    for (auto &it : ump) {
      if (it.second.size() >= k) {
        cnt1++;
        for (int i = 0; i < k; i++) {
          ans[it.second[i]] = idx;
          idx++;
          if (idx == k + 1) idx = 1;
        }
        for (int i = 0; i < it.second.size() - k; i++)
          ans[it.second[i + k]] = 0;
      } else {
        temp = idx;
        for (int i = 0; i < it.second.size(); i++) {
          ans[it.second[i]] = idx;
          idx++;
          if (idx == k + 1) idx = 1;
        }
        cnt2 += it.second.size();
      }
    }
    long long lim = cnt1 + cnt2 / k;
    for (int i = 0; i < n; i++) {
      cnt3[ans[i]]++;
      if (cnt3[ans[i]] <= lim)
        cout << ans[i] << " ";
      else
        cout << "0"
             << " ";
    }
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  xagar();
  return 0;
}
