#include<iostream>
#define MAX_BALL 10
using namespace std;

int ball[MAX_BALL];
int n;
int r = 0, l = 0;
bool flag = 0;

void dfs(int x)
{
	if (x == MAX_BALL)
	{
		flag = true;
		return;
	}
	if (ball[x] >= r)
	{
		r = ball[x];
		dfs(x + 1);
	}
	if (ball[x] >= l)
	{
		l = ball[x];
		dfs(x + 1);
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		flag = false;
		r = 0;
		l = 0;
		for (int j = 0; j < MAX_BALL; j++)
			cin >> ball[j];
		dfs(0);
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}