#include<iostream>
#include<cstring>
#include<stack>
using namespace std;
int const MAXN=1e2+9;
int n;
int t1=1;
int t2=1;
int a[MAXN]={0};
int s1[MAXN]={0};
int s2[MAXN]={0};
bool used[MAXN]={false};

bool check(int *s,int t)
{
	for(int i=1;i<t-1;i++)
		if(!(s[i]<s[i+1]))
			return false;
	return true;
}

bool dfs(int i)
{
	if(i==n)
	{
		t2=1;
		for(int i=1;i<=n;i++)
			if(!used[i])
				s2[t2++]=a[i];
		if(check(s1,t1)&&check(s2,t2))
			return true;
		return false;
	}
	if(dfs(i+1))
		return true;
	if(a[i]>=s1[t1-1])
	{
		used[i]=true;
		s1[t1++]=a[i];
		if(dfs(i+1))
			return true;
		used[i]=false;
		t1--;
	}
	return false;
}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		n=10;
		t1=1;
		t2=1;
		memset(a,0,sizeof(a));
		memset(s1,0,sizeof(s1));
		memset(s2,0,sizeof(s2));
		memset(used,false,sizeof(used));
		for(int i=1;i<=n;i++)
			cin>>a[i];
		s1[t1++]=a[1];
		used[1]=true;
		if(dfs(2))
			cout<<"YES\n";
		else
			cout<<"NO\n";
	}
	return 0;
}
