#include<stdio.h>
int i,b[11],x;
void dfs(int i,int left,int right)
{
	if(i==10)
	{
		x=1;
		return;
	}
	if(x)
	{
		return;
	} 
	if(b[i]>left)
	{	
		dfs(i+1,b[i],right);
	}
	if(b[i]>right)
	{
		dfs(i+1,left,b[i]);
	}
}
int main()
{
	int a;
	while(scanf("%d",&a)!=EOF)
	{
		while(a--)
		{
			x=0;
			for(i=0;i<10;i++)
			{
				scanf("%d",&b[i]);
			}
			dfs(0,0,0);
			if(x==1)
			{
				printf("YES\n");
			}
			else
			{
				printf("NO\n");
			}
		}
	}
	return 0;	
} 

