#include<iostream>
#include<fstream>
#include<stack>
#include<vector>
#include<cstring>
using namespace std;
int a[11];
int b[11];
int c[11];
int flag;
void dfs(int x,int y,int z)
{
	if(x==9)
		flag=1;
	if(a[x]<b[y]&&a[x]<c[z])
		return;
	if(a[x]>b[y])
	{
		b[y+1]=a[x];
		dfs(x+1,y+1,z);
	}
	if(a[x]>c[z])
	{
		c[z+1]=a[x];
		dfs(x+1,y,z+1);
	}
}
int main()
{
	//freopen("3.txt","r",stdin);
	int n;
	cin >> n;
	while(n--)
	{
	flag=0;
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	for(int i=0;i<10;i++)
		cin >> a[i];
	dfs(0,0,0);
	if(flag)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	}	
	return 0;
}