#include <iostream>

using namespace std;

bool flag;
void Search(int a[], int pos, int b, int c)
{
	if(pos == 10)
	{
		flag = true;
	}
	if(b > a[pos] && c > a[pos])
	{
		return;
	}
	if(b < a[pos])
	{
		Search(a, pos + 1, a[pos], c);
	}
	if(c < a[pos])
	{
		Search(a, pos + 1, b, a[pos]);
	}
}

void solve()
{
	int N;
	cin >> N;
	while(N--)
	{
		flag = false;
		int A[10];
		for(int i = 0; i < 10; ++i)
		{
			cin >> A[i];
		}
		int B = 0, C = 0;
		Search(A, 0, B, C);
		if(flag)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}