#include <iostream>
#include <algorithm>
using namespace std;

int main(void)
{
	int N;
	cin >> N;

	while(N > 0){
		int data[10];
		int a=0,b=-1;
		for(int i = 0; i < 10; i++){
			cin >> data[i];

		}

		for(int i = 0; i < 10; i++){
			if(a > data[i] && b > data[i]){
				a = -1;
				break;
			}
			if(data[i] > a && a > b)
				a = data[i];
			else if(a > data[i] && data[i] > b)
				b = data[i];


		}

		if(a < 0)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;

		N--;
	}

	return 0;

}