#include<iostream>
#include <stack> 
using namespace std;
int ar[10];
stack<int> a,b;
bool dfs(int i)
{
	bool aflag = false,bflag = false;
	if(i!=9)
	{
		if(a.empty()||a.top()<ar[i])
		{
			a.push(ar[i]);
			aflag = dfs(i+1);
		}
		if(b.empty()||b.top()<ar[i])
		{
			b.push(ar[i]);
			bflag = dfs(i+1);
		}
		return aflag|bflag;
	}
	if(i==9)
	{
		if(a.empty()||a.top()<ar[i])
		{
			a.push(ar[i]);
			aflag = true;
		}
		if(b.empty()||b.top()<ar[i])
		{
			b.push(ar[i]);
			bflag = true;
		}
		return aflag|bflag;
	}
}
int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		for(int i = 0;i<10;i++)
			cin >> ar[i]; 
		cout<<(dfs(0)?"YES":"NO")<<endl;
	}
 } 