#include <iostream>
using namespace std;
int num[10];
bool dfs(int start, int topl, int topr)
{
	if (start == 9)
	{
		if (num[start] > topl || num[start] > topr)
			return true;
		else
			return false;
	}
	else
	{
		bool b1 = false, b2 = false;
		if (num[start] > topl)
			b1=dfs(start + 1, num[start], topr);
		if (num[start] > topr)
			b2 = dfs(start + 1, topl, num[start]);
		return (b1 || b2);
	}
}
	
int main()
{
	int k;
	cin >> k;
	while (k--)
	{
		for (int i = 0; i <= 9; ++i)
			cin >> num[i];
		if (dfs(0,0,0))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}