#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define RG register int
#define rep(i,a,b)	for(RG i=a;i<=b;++i)
#define per(i,a,b)	for(RG i=a;i>=b;--i)
#define ll long long
#define inf (1<<29)
using namespace std;
int T,n=10,flg;
int num[15],rec[15],a[15],b[15];
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}

void judge()
{
	int la=0,lb=0;
	rep(i,1,n)	if(rec[i]==1)	a[++la]=num[i];
				else			b[++lb]=num[i];
	rep(i,2,la)	if(a[i-1]>a[i])	return;
	rep(i,2,lb)	if(b[i-1]>b[i])	return;
	flg=1;return;
}

void dfs(int step)
{
	if(flg)	return;
	if(step>n){judge();return;}
	rec[step]=1;dfs(step+1);
	rec[step]=0;dfs(step+1);
}

int main()
{
	T=read();
	while(T--)
	{
		rep(i,1,n)	num[i]=read();
		flg=0;
		dfs(1);
		puts(!flg?"NO":"YES");
	}
	return 0;
}
