#include<iostream>
#include<cstring>
using namespace std;
void dfs(int b[11],int c[11],int m,int k,int t);//a中，b中，c中游标
int a[10];
int flag;
int main()
{
	int N;
	cin >> N;
	while (N--)
	{
		for (int i = 0; i < 10; i++)
			cin >> a[i];
		int b[10];
		int c[10];
		b[0] = 0;
		c[0] = 0;
		flag = 0;
		dfs(b, c, 0, 0, 0);
		if (flag== 1)
			cout << "YES" << endl;
		else 
			cout << "NO" << endl;
	}
	return 0;
}
void dfs(int b[11], int c[11], int m, int k, int t)
{
	int ma = m;
	int kb = k;
	int tc = t;
	int i;
	int x[11], y[11];             //用x,y去中间值，好进行回溯
	if (ma == 10)
		flag=1;
	else
	{
		for (i = 0; i <= kb; i++)
		{
			x[i] = b[i];
		}
		for (i = 0; i <= tc; i++)
		{
			y[i] = c[i];
		}
		/*if (x[kb] > a[ma] && y[tc] > a[ma])  //两个都大  不要直接return 应该返回 找其他的枝丫
			return 0;*/
		if (x[kb] > a[ma] && y[tc] < a[ma])
		{ 
			tc++;
			y[tc] = a[ma];
			ma++;
			dfs(x, y, ma, kb, tc);
		}
		else if (x[kb] < a[ma] && y[tc] > a[ma])
		{
			kb++;
			x[kb] = a[ma];
			ma++; 
			dfs(x, y, ma, kb, tc);
		}
		else if (x[kb] < a[ma] && y[tc] < a[ma])
		{
			kb++;
			x[kb] = a[ma];
			ma++;
			dfs(x, y, ma, kb, tc);
			ma--; kb--;
            tc++;
			y[tc] = a[ma];
			ma++;
			dfs(x, y, ma, kb, tc);
			ma--; tc--;
		}
	}
}


