#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(void)
{
	int n;

	cin >> n;
	while (n-- != 0)
	{
		int A[10] = {}, B[10] = {}, C[10] = {}, countb = 0, countc = 0;
		bool f = true;
		for (int i = 0; i < 10; i++)
		{
			cin >> A[i];
		}
		B[countb++] = A[0];
		for (int i = 1; i < 10; i++)
		{
			if (B[countb - 1] < A[i]) B[countb++] = A[i];
			else if (countc == 0) C[countc++] = A[i];
			else if (B[countb - 1] > A[i] && C[countc - 1] < A[i]) C[countc++] = A[i];
			else f = false;
		}
		//for (int i = 0; i < sizeof(B) / sizeof(*B); i++) cout << "B" << i << " =" <<B[i] << endl;
		//for (int i = 0; i < sizeof(C) / sizeof(*C); i++) cout << "C" << i << "=" << C[i] << endl;
		if (f == true) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}
