#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pi acos(-1)
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define rep(i,x,n) for(int i=x;i<n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
using namespace std;
typedef pair<int,int>P;
const int MAXN=100010;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int a[12],b[12],cnt,book[12];
bool flag;
void dfs(int k)
{
	if(k == 11)
	{
		int last = 0;
		for(int i=1;i<=10;i++)
		{
			if(!book[i])
			{
				if(a[i] < last)
				return ;
				last = a[i];
			}
		}
		flag = 1;
		return ;
	}
	for(int i=k+1;i<=10;i++)
	{
		if(a[i] > b[cnt - 1])
		{
			book[i] = 1;
			dfs(i+1);
			book[i] = 0;
		}
	}
}
int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		for(int i=1;i<=10;i++)
		cin >> a[i];
		for(int i=1;i<=10;i++)
		{
			cnt = 1;
			dfs(i);
			if(flag)
			{
				cout << "YES\n";
				break;
			}
		}
		if(!flag)
		cout << "NO\n";
		flag = 0;
	}
 	return 0;
}