#include <iostream>
#include <stdlib.h>
#include <queue>

using namespace std;

queue<int> A;
queue<int> B;
int num[10];

bool DFS(int i) {
	if (i < 10)
	{
		int pos = i;
		int temp = num[i];
		for (int j = i; j < 10; j ++)
		{
			if (num[j] < temp)
			{
				pos = j;
				break;
			}
		}
		for (int k = i; k < pos; k++)
		{
			if (A.empty())
			{
				A.push(num[k]);
			}
			else
			{
				int tempNum = A.back();
				if (num[k] > tempNum)
				{
					A.push(num[k]);
				}
				else
				{
					return false;
				}
			}
		}
		if (B.empty())
		{
			B.push(num[pos]);
		}
		else
		{
			int temp_B = B.back();
			if (temp_B < num[pos])
			{
				B.push(num[pos]);
			}
			else
			{
				return false;
			}
		}
		DFS(pos+1);
	}
	return true;
}
int main() {
	int n;
	while (cin >> n)
	{
		while (n-- > 0)
		{
			for (int i = 0; i < 10; i++)
			{
				cin >> num[i];
			}
			if (DFS(0))
			{
				cout << "YES" << endl;
			}
			else {
				cout << "NO" << endl;
			}
		}
	}
	return 0;
}