#pragma GCC optimize("Ofast", "inline", "-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
# include <bits/stdc++.h>
using namespace std ;
int n , m ;
int a[200005] ;
typedef pair< int , int > pii ;
int cnt1 = 0 , cnt2 = 0 ;
int Read()
{
int num=0,k=1; //k是正负数标记
char c=getchar();
while(c!='-'&&(c<'0'||c>'9')) c=getchar();//注意判断'-'
if(c=='-')
{
k=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
num=(num<<3)+(num<<1)+(c^48);//num<<3相当于num*8,num<<1相当于num*2,
c=getchar(); //c^48利用位运算优化,相当于c-'0' ,但是一定要加括号
}
return num*k;
}
void print1(int x)
{
if(x>9) print1(x/10); //把这个数一位一位的输出
putchar(x%10+'0');
}
struct pq1
{
priority_queue < pii > q1 , q2 ;
priority_queue < pii , vector < pii > , greater < pii > > q3 , q4 ;
void init()
{
while ( q1.size() ) q1.pop() ;
while ( q2.size() ) q2.pop() ;
while ( q3.size() ) q3.pop() ;
while ( q4.size() ) q4.pop() ;
}
void push( pii x )
{
// printf("push:{%d,%d}\n" , x.first , x.second) ;
q1.push( x ) ;
q3.push( x ) ;
}
void del( pii x )
{
// printf("pop:{%d,%d}\n" , x.first , x.second) ;
q2.push( x ) ;
q4.push( x ) ;
}
pii maxv()
{
while ( q1.size() && q2.size() )
{
if ( q1.top() != q2.top() ) return q1.top() ;
q1.pop() , q2.pop() ;
}
return q1.top() ;
}
pii minv()
{
// puts("qmin:") ;
while ( q3.size() && q4.size() )
{
// printf("{%d,%d} {%d,%d}\n" , q3.top().first , q3.top().second , q4.top().first , q4.top().second) ;
if ( q3.top() != q4.top() ) return q3.top() ;
q3.pop() , q4.pop() ;
}
// printf("{%d,%d}\n" , q3.top().first , q3.top().second) ;
return q3.top() ;
}
} q ;
bool check( int v )
{
// printf("check:%d\n" , v) ;
q.init() ;
for ( int i = 1 ; i <= m ; i++ ) q.push( { 0 , i } ) ;
for ( int i = 1 ; i <= n ; i++ )
{
if ( a[i] == 1 )
{
auto now = q.minv() ;
// printf("now:%d %d\n" , now.first , now.second) ;
q.del( now ) ;
if ( now.first + 1 > v ) return false ;
q.push( { now.first + 1 , now.second } ) ;
}
else
{
auto now = q.maxv() ;
if ( now.first == 0 ) continue ;
q.del( now ) ;
q.push( { now.first - 1 , now.second } ) ;
}
}
return true ;
}
int ans[200005] ;
void solve()
{
scanf("%d%d" , &n , &m) ;
for ( int i = 1 ; i <= n ; i++ ) a[i] = Read() ;
int l = 0 , r = n ;
while ( l < r )
{
int mid = ( l + r ) >> 1 ;
if ( check( mid ) ) r = mid ;
else l = mid + 1 ;
}
q.init() ;
for ( int i = 1 ; i <= m ; i++ ) q.push( { 0 , i } ) ;
for ( int i = 1 ; i <= n ; i++ )
{
if ( a[i] == 1 )
{
auto now = q.minv() ;
// printf("now:%d %d\n" , now.first , now.second) ;
q.del( now ) ;
print1( now.second ) ;
putchar(' ') ;
// printf("%d " , now.second) ;
q.push( { now.first + 1 , now.second } ) ;
}
else
{
auto now = q.maxv() ;
print1( now.second ) ;
putchar(' ') ;
// printf("%d " , now.second) ;
if ( now.first == 0 ) continue ;
q.del( now ) ;
q.push( { now.first - 1 , now.second } ) ;
}
}
// printf("%d\n" , l) ;
puts("") ;
}
int main()
{
// freopen("1.in" , "r" , stdin) ;
// freopen("1.out" , "w" , stdout) ;
int t ;
scanf("%d" , &t) ;
while ( t -- ) solve() ;
// printf("%d %d\n" , cnt1 , cnt2) ;
return 0 ;
}