#include<cstdio>  
int n,l1,l2,a[15];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
	    bool f=0;l1=-1;l2=0;
		for(int j=1;j<=10;j++)
			scanf("%d",&a[j]);
		for(int j=1;j<=10;j++)
		if(!f)
		{
			if(a[j]<l1&&a[j]<l2){f=1;printf("No\n");break;}
			if(l1>l2){if(a[j]>l1)l1=a[j];else l2=a[j];} 
			else{if(a[j]>l2)l2=a[j];else l1=a[j];}
		}
		if(!f)printf("YES\n");a
	}
}