#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<deque>
#define INF int(1e9)
using namespace std;
int read()
{
    int f=1,x=0;
    char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
    return f*x;
}
bool flag;
int ball[11];
void DFS(int left,int right,int now)
{
	if(now>10)
	{
		flag=1;	
		return ;
	}
	if(ball[now]>left&&ball[now]>right) 
		return ;	
	if(ball[now]<left)
		DFS(ball[now],right,now+1);
	else
		DFS(left,ball[now],now+1);
	return ;
}
int main()
{
	int t=read();
	while(t!=0)
	{
		t--;
		flag=0;
		for(int i=10;i>=1;i--)
			ball[i]=read();
		DFS(INF,INF,1);
		if(flag==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
    return 0;
}