This problem is an extension of the problem "Wonderful Coloring - 1". It has quite many differences, so you should read this statement completely.

Recently, Paul and Mary have found a new favorite sequence of integers a_1, a_2, ..., a_n. They want to paint it using pieces of chalk of k colors. The coloring of a sequence is called wonderful if the following conditions are met:

  1. each element of the sequence is either painted in one of k colors or isn't painted; 
  2. each two elements which are painted in the same color are different (i. e. there's no two equal values painted in the same color); 
  3. let's calculate for each of k colors the number of elements painted in the color — all calculated numbers must be equal; 
  4. the total number of painted elements of the sequence is the maximum among all colorings of the sequence which meet the first three conditions. 



E. g. consider a sequence a=[3, 1, 1, 1, 1, 10, 3, 10, 10, 2] and k=3. One of the wonderful colorings of the sequence is shown in the figure.

<image> The example of a wonderful coloring of the sequence a=[3, 1, 1, 1, 1, 10, 3, 10, 10, 2] and k=3. Note that one of the elements isn't painted.

Help Paul and Mary to find a wonderful coloring of a given sequence a.

Input

The first line contains one integer t (1 ≤ t ≤ 10000) — the number of test cases. Then t test cases follow.

Each test case consists of two lines. The first one contains two integers n and k (1 ≤ n ≤ 2⋅10^5, 1 ≤ k ≤ n) — the length of a given sequence and the number of colors, respectively. The second one contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n).

It is guaranteed that the sum of n over all test cases doesn't exceed 2 ⋅ 10^5.

Output

Output t lines, each of them must contain a description of a wonderful coloring for the corresponding test case.

Each wonderful coloring must be printed as a sequence of n integers c_1, c_2, ..., c_n (0 ≤ c_i ≤ k) separated by spaces where

  * c_i=0, if i-th element isn't painted; 
  * c_i>0, if i-th element is painted in the c_i-th color. 



Remember that you need to maximize the total count of painted elements for the wonderful coloring. If there are multiple solutions, print any one.

Example

Input


6
10 3
3 1 1 1 1 10 3 10 10 2
4 4
1 1 1 1
1 1
1
13 1
3 1 4 1 5 9 2 6 5 3 5 8 9
13 2
3 1 4 1 5 9 2 6 5 3 5 8 9
13 3
3 1 4 1 5 9 2 6 5 3 5 8 9


Output


1 1 0 2 3 2 2 1 3 3
4 2 1 3
1
0 0 1 1 0 1 1 1 0 1 1 1 0
2 1 2 2 1 1 1 1 2 1 0 2 2
1 1 3 2 1 3 3 1 2 2 3 2 0

Note

In the first test case, the answer is shown in the figure in the statement. The red color has number 1, the blue color — 2, the green — 3.
12
10 3
3 1 1 1 1 10 3 10 10 2
4 4
1 1 1 1
1 1
1
13 1
3 1 4 1 5 9 2 6 5 3 5 8 9
13 2
3 1 4 1 5 9 2 6 5 3 5 8 9
13 3
3 1 4 1 5 9 2 6 5 3 5 8 9
10 3
3 1 1 1 1 10 3 10 10 2
4 4
1 1 1 1
1 1
1
13 1
3 1 4 1 5 9 2 6 5 3 5 8 9
13 2
3 1 4 1 5 9 2 6 5 3 5 8 9
13 3
3 1 4 1 5 9 2 6 5 3 5 8 9
 6
10 3
3 1 1 1 1 10 3 10 10 2
4 4
1 1 1 1
1 1
1
13 1
3 1 4 1 5 9 2 6 5 3 5 8 9
13 2
3 1 4 1 5 9 2 6 5 3 5 8 9
13 3
3 1 4 1 5 9 2 6 5 3 5 8 9

2 1 2 3 0 1 3 2 3 1 
1 2 3 4 
1 
1 1 1 0 1 1 1 1 0 0 0 1 0 
2 1 2 2 1 1 1 1 2 1 0 2 2 
1 1 3 2 1 3 3 1 2 2 3 2 0 
2 1 2 3 0 1 3 2 3 1 
1 2 3 4 
1 
1 1 1 0 1 1 1 1 0 0 0 1 0 
2 1 2 2 1 1 1 1 2 1 0 2 2 
1 1 3 2 1 3 3 1 2 2 3 2 0 
 2 1 2 3 0 1 3 2 3 1 
1 2 3 4 
1 
1 1 1 0 1 1 1 1 0 0 0 1 0 
2 1 2 2 1 1 1 1 2 1 0 2 2 
1 1 3 2 1 3 3 1 2 2 3 2 0 

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define ll                      long long
#define int                     ll
#define FIO                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld                      long double
#define ull                     unsigned long long
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define afo(i,x)                for(auto &i:x)
#define vi                      vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                     unordered_map
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define vvi                    vector<vi>
#define mod                     1000000009
#define MIN                     -1e9
#define pi                      3.1415926535897932384626433832795
 
using namespace std;
using namespace __gnu_pbds;
 
template<class T> using oset =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
 
void INPUT()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

void solve(){ 
  int n,k;
  cin>>n>>k;

  int a[n];
  unordered_map<int,int>x;
  fo(i,0,n-1)
  {
    cin>>a[i];
    x[a[i]]++;
  }

  int ans[n];
  // set<int>z;
  unordered_map<int,int>col;
  unordered_map<int,int>go,comp;
  // vi remcol;
  int rem=0;
  afo(i,x)
  {
    if(i.second>=k)
      col[i.first]=1;
    else if (i.second>1)
    {
      go[i.first]=i.second;
      comp[i.first]=1;
      rem+=i.second;
    }  
    else
      rem++;
  }

  vi b;
  b.resize(n,-1);

  set<int>s,notfull;
  int remcolor=1;

  // afo(i,go)
  // {
  //   cout<<i.first<<" "<<i.second<<endl;
  // }
  fo(i,0,n-1)
  {
    if(col[a[i]]>0 and col[a[i]]<=k)
    {
      b[i]=col[a[i]];
      col[a[i]]++;
    }
    else if(col[a[i]]>0)
    {
      b[i]=0;
    }
    else if(go[a[i]]>0 and s.find(a[i])==s.end())
    {
      if((remcolor==1 and (rem)>=k) or (remcolor!=1 and remcolor>0))
      {
        int diff=remcolor+x[a[i]]-1;
        if(diff>k)
          diff-=k;
        
        if(rem-x[a[i]]+diff>=k)
        {
          go[a[i]]=remcolor;
          b[i]=go[a[i]];
          go[a[i]]++;
          remcolor=remcolor+x[a[i]];
          
          if(remcolor>k)
            remcolor-=k;

          if(go[a[i]]>k)
            go[a[i]]=1;
        }
        
        else
        {
          // cout<<rem;
          // cout<<rem-x[a[i]]+diff;
          go[a[i]]=remcolor;
          b[i]=go[a[i]];
          go[a[i]]++;
          notfull.insert(a[i]);
          remcolor=-1;
          // cout<<a[i]<<0<<endl;
        }
      
      }

      else if(rem<k)
      {
        go[a[i]]=0;
        b[i]=go[a[i]];
        remcolor=-1;
        // cout<<1<<endl;
      }

      rem-=x[a[i]];
      s.insert(a[i]);
    }
    else if(s.find(a[i])!=s.end())
    {
      if(go[a[i]]>0)
      {
        b[i]=go[a[i]];
        go[a[i]]++;
        if(go[a[i]]>k and notfull.find(a[i])==notfull.end())
          go[a[i]]-=k;
        else if(go[a[i]]>k)
          go[a[i]]=0;
      }
      else
      {
        b[i]=0;
      }
    }

  }

  // cout<<remcolor<<endl;
  if(rem>0)
  {
    fo(i,0,n-1)
    {
      if(b[i]==-1 and remcolor>0 and remcolor+rem-1>=k)
      {
        b[i]=remcolor;
        remcolor++;
        rem--;
        if(remcolor>k and rem>=k)
        {
          remcolor=1;
        }
        else if(remcolor>k)
        {
          remcolor=-1;
        }
      }
      else if(b[i]==-1)
      {
        b[i]=0;
      }
    }
  }
  fo(i,0,n-1)
  {
    cout<<b[i]<<" ";
  }

  cout<<endl;

}

signed main() {
 
  FIO
  INPUT();
  int t;
   t = 1;
  cin >> t;
  fo(i, 0, t - 1)
  {
    solve();
  }
  return 0;
}