#include <iostream>
#include <stack>
using namespace std;
int a[10];
stack<int> b[2];
bool dfs(int i, int to)
{
	if (i == 9)
	{
		if (a[i] > b[to].top() || a[i] > b[!to].top())
			return true;
		else
			return false;
	}
	else if (a[i] > b[to].top() && a[i] > b[!to].top())
	{
		b[to].push(a[i]);
		if (dfs(i+1, to))
			return true;
		b[to].pop();
		b[!to].push(a[i]);
		if (dfs(i+1, !to))
			return true;
		return false;
	}
	else if (a[i] > b[to].top())
	{
		b[to].push(a[i]);
		if (dfs(i+1, to))
			return true;
		b[to].pop();
		return false;
	}
	else if (a[i] > b[!to].top())
	{
		b[!to].push(a[i]);
		if (dfs(i+1, !to))
			return true;
		b[!to].pop();
		return false;
	}
	else
		return false;
}
int main()
{
	int n, i, j;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < 10; j++)
			cin >> a[j];
		b[0].push(0);
		b[1].push(0);
		if (dfs(0, 0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}