#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int a[10], b[10], c[10];
int N;
int top1 = -1, top2 = -1;

bool dfs(int i)
{
	if (i == 10)
		return true;
	if (a[i] > b[top1] || top1 == -1)
		b[++top1] = a[i];
	else if (a[i] > c[top2] || top2 == -1)
		c[++top2] = a[i];
	else return false;
	dfs(i + 1);
}

int main()
{
	scanf("%d", &N);
	while (N--)
	{
		for (int i = 0; i < 10; i++)
			scanf("%d", &a[i]);
		if (dfs(0))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		memset(b, 0, sizeof(b));
		memset(c, 0, sizeof(c));
		top1 = top2 = -1;
	}
	return 0;
}
