#include <iostream>
#include <cstdio>

using namespace std ;
int flag ;
int q[11];

void dfs(int pos, int left,int right)
{
	if (pos==10) 
	{
		flag = 1 ;
		return ;
	}
	if (q[pos] > left )
	dfs(pos+1 , q[pos] , right);
	
	if (q[pos] > right)
	dfs (pos+1,left ,q[pos]);
	
}
int main ()
{
	
	int n;
	cin >> n ;
	for (int i=0;i<n;i++)
	{
		flag = 0 ;
		for (int i=0;i<10;i++)
			cin >> q[i];
		dfs(0,-1,-1);
		if (flag == 1)
		cout <<"YES"<<endl;
		else 
		cout <<"NO"<<endl;
	}
	
	return 0;
}
