#include<iostream>


using namespace std;

int data[11],N;
int a[11],b[11];
int na,nb;

bool dfs(int a[],int b[],int k)
{
	if(k==11)
	  return true;
	if(data[k]>a[na])
	{
		na++;
		a[na] = data[k];
		
		if(dfs(a,b,k+1))
		 return true;
		a[na] = 0;
		na--;
	}
	if(data[k]>b[nb])
	{
		nb++;
		b[nb] = data[k];
	    if(dfs(a,b,k+1))
	     return true;
		b[nb]=0;
		nb--;
	}
	
	return false;
	
}
int main()
{
	cin>>N;
	int time=1;
	while(time++<=N)
	{
		for(int i=1;i<=10;i++)
		{
		cin>>data[i];
		a[i]=0;
		b[i]=0;
		}
		na = nb = 0;
		
		if(dfs(a,b,1)==true)
		cout<<"YES"<<endl;
		else
		 cout<<"NO"<<endl;
	}
}
