import java.util.ArrayList;
import java.util.Scanner;
import java.util.*;
class Weakmid {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int numberOfCases = in.nextInt();
for(int i=0;i<numberOfCases;i++)
{
int N = in.nextInt();
ArrayList<Entry> l = new ArrayList<Entry>();
for(int j=0;j<N;j++)
{
int t = in.nextInt();
Entry e = new Entry();
e.value=t;
e.noOfDaysBeforeStackTop=0;
e.indx=j;
l.add(e);
}
Stack<Entry> st = new Stack();
int day = 0;
int[] result = new int [N];
for(Entry e:l)
{
if(st.isEmpty() || st.size()==1)
st.push(e);
else
{
if(st.peek().value<e.value && st.get(st.size()-2).value>st.peek().value)
{
do{
int removalDay = Integer.max(st.get(st.size()-2).noOfDaysBeforeStackTop, day) + 1;
result[st.pop().indx] = removalDay;
st.peek().noOfDaysBeforeStackTop = removalDay;
day++;
}while(st.size()>2 && (st.peek().value<e.value && st.get(st.size()-2).value>st.peek().value));
st.push(e);
day=0;
}
else
{
st.peek().noOfDaysBeforeStackTop=0;
st.push(e);
day=0;
}
}
}
for(Entry e1:st)
result[e1.indx]=0;
for(int t=0;t<result.length-1;t++)
System.out.print(result[t] + " ");
System.out.print(result[result.length-1]);
System.out.println("\n");
}
}
static class Entry{
int value;
int indx;
int noOfDaysBeforeStackTop;
}
}