import java.util.*; public class non { static void min(long[] a, int[] b, int start, int end, int step, int root){ Stack st = new Stack<>(); for(int i=start;i!=end;i+=step){ while(!st.isEmpty() && a[st.lastElement()] >= a[i]) st.pop(); if(st.isEmpty()) b[i] = root; else b[i] = st.lastElement(); st.push(i); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); while(T-->0){ int n = sc.nextInt(); long[] a = new long[n]; for(int i=0;i