package com.itheima.com;
import java.util.Scanner;
public class Dem2 {
//特殊数据2 3 1 1
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int count = sc.nextInt();
for (int i = 0; i < count ; i++) {
int n = sc.nextInt();
int[] arr = new int[n] ;
for (int j = 0; j < n; j++) {
arr[j] = sc.nextInt();
}
int candy = candy(arr,n);
System.out.println(candy);
}
}
public static int candy(int[] ratings,int n)
{
int size= n;
if(size ==0)
return -1;
if(size ==1)
return 1;
int[] ans = new int[n+1];
ans[0]=1;
//第一轮:保证后面比前面权值高的孩子,必定多得1个糖果
for(int i=1; i<size; ++i)
{
if(ratings[i] >ratings[i-1])
ans[i] = ans[i-1]+1;
else
ans[i]=1;
}
//第二轮:保证前面比后面权值高的孩子,必定多得1个糖果
for(int i=size-2; i>=0; --i)
{
if(ratings[i]> ratings[i+1] && ans[i] <= ans[i+1])
{
ans[i]=ans[i+1]+1;
}
}
//处理第一个和最后一个(很容易出错的地方)
if( size >2 && ratings[0]> ratings[size -1 ] && ans[0] <= ans[size -1 ]){
ans[0]+=ans[size-1];
for(int i=1; i<size; ++i)
{
if(ratings[i] > ratings[i-1] && ans[i] <= ans[i-1] )
ans[i] = ans[i-1]+1;
else
break;
}
}
if( size >2 && ratings[0]< ratings[size -1 ] && ans[0] >= ans[size -1 ]){
ans[size -1]+=ans[0];
for(int i=size-2; i>=0; --i)
{
if(ratings[i]> ratings[i+1] && ans[i] <= ans[i+1])
{
ans[i]=ans[i+1]+1;
}else{
break;
}
}
}
int sum=0;
for(int i=0; i<size; ++i)
{
System.out.print(ans[i]+" ");
sum+=ans[i];
}
return sum;
}
}