#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <stack>
using namespace std;
#define N 10003
#define PI 3.14159265358979323
#define INF 0x3f3f3f3f
#define MOD 100000007
#define ll long long
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
int n,a[N];
int gp[11];
int W,H;
int cnt=0;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int us[11];
void dfs ( int x )
{
	int i;
	int nx,ny;
	i=1;
	while ( i<10&&(us[x+i]==1||gp[x+i]<=gp[x]) )
	i++;
	
	if ( x+i<10&&gp[x+i]>gp[x]&&us[x+i]==0 )
	{
		us[x+i]=1;
		dfs(x+i);
	}

}

//template < class T> void read ( T &x ){	char c;int sign=1;x=0;while ( c=getchar(),(c>'9'||c<'0')&&c!='-') ;if ( c=='-' ){sign=-1;}else x=c-'0';while ( c=getchar(),c<='9'&&c>='0' ){x=x*10+c-'0';}x=x*sign;}
int main ( )
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int i,j;
	int f;
	cin>>n;
	while (n-- )
	{
		f=0;
		memset ( us,0,sizeof(us));
		for ( i=0;i<10;i++ )
		{
			cin>>gp[i];
		}
		cnt=0;
		
		for ( i=0;i<10;i++ )
		{
			if ( us[i]==0 )
			{
				cnt++;
				us[i]=1;
				dfs(i);
			}
		}
		
		if ( cnt==2 )
		f=1;
		
		
		if ( f )
		printf("YES\n");
		else
		printf("NO\n");
		
		//printf( "%d\n",cnt); 
		
	} 
	
	return 0;
}
	

