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

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

bool dfs(int x,bool d)//1 is right, 0 is left
{
	if (x == MAX_BALL)
		return true;
	if (d)
		r = ball[x];
	else
		l = ball[x];
	if (ball[x + 1] >= r)
		return dfs(x + 1, 1);
	if (ball[x + 1] >= l)
		return dfs(x + 1, 0);
	return false;
}

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