import java.io.*; import java.util.*; class Main { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int t=Integer.parseInt(bu.readLine()); while(t-->0) { int n=Integer.parseInt(bu.readLine()); ArrayList g[]=new ArrayList[n]; int i,a[]=new int[n],b[]=new int[n]; st=new int[4*n]; mt=new int[4*n]; Arrays.fill(st,Integer.MAX_VALUE); String s[]=bu.readLine().split(" "); for(i=0;i(); for(i=0;i=b[i] && queryMx(0,n-1,ex,i,0)<=b[i]); ex=higher(g[b[i]],i); here|=(ex>=i && query(0,n-1,i,ex,0)>=b[i] && queryMx(0,n-1,i,ex,0)<=b[i]); //System.out.println(here); ok&=here; } if(ok) sb.append("Yes\n"); else sb.append("No\n"); } System.out.print(sb); } static int lower(ArrayList a,int x) { int l=0,r=a.size()-1,mid,ans=Integer.MAX_VALUE; while(l<=r) { mid=(l+r)>>1; if(a.get(mid)<=x) { ans=a.get(mid); l=mid+1; } else r=mid-1; } return ans; } static int higher(ArrayList a,int x) { int l=0,r=a.size()-1,mid,ans=-1; while(l<=r) { mid=(l+r)>>1; if(a.get(mid)>=x) { ans=a.get(mid); r=mid-1; } else l=mid+1; } return ans; } static int st[]; static void update(int ss,int se,int i,int v,int n) { if(ss==se) { st[n]=v; return; } int m=(ss+se)>>1; if(i<=m) update(ss,m,i,v,2*n+1); else update(m+1,se,i,v,2*n+2); st[n]=Math.min(st[2*n+1],st[2*n+2]); } static int query(int ss,int se,int qs,int qe,int n) { if(ss>se || qese) return Integer.MAX_VALUE; if(qs<=ss && qe>=se) return st[n]; int m=(ss+se)>>1; return Math.min(query(ss,m,qs,qe,2*n+1),query(m+1,se,qs,qe,2*n+2)); } static int mt[]; static void updateMx(int ss,int se,int i,int v,int n) { if(ss==se) { mt[n]=v; return; } int m=(ss+se)>>1; if(i<=m) updateMx(ss,m,i,v,2*n+1); else updateMx(m+1,se,i,v,2*n+2); mt[n]=Math.max(mt[2*n+1],mt[2*n+2]); } static int queryMx(int ss,int se,int qs,int qe,int n) { if(ss>se || qese) return 0; if(qs<=ss && qe>=se) return mt[n]; int m=(ss+se)>>1; return Math.max(queryMx(ss,m,qs,qe,2*n+1),queryMx(m+1,se,qs,qe,2*n+2)); } }