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

int main()
{
	int ball = 10;
	int n,k;
	cin >> n;
	queue<int> a;
	int b = 0 , c = 0;
	queue<bool> flag;


	for (int i=0; i < n; i++){
		for (int j=1; j <= ball; j++){
			cin >> k;
			a.push( k );
		}
		b = a.front();
		a.pop();
		
		for (int j=1; j <= (ball-1); j++){
			if (a.front() > b && a.front() > c){
				if (a.front() - b > a.front() - c)
					c = a.front();

				else
					b = a.front();

			}else if(a.front() > b){
				b = a.front();
			
			}else if(a.front() > c){
				c = a.front();
			
			}else {
				flag.push(false);
				j = ball;
			}
			a.pop();
			if (j == (ball-1))
				flag.push(true);
		}
	}

	for (int i = 0; i < n; i++){
		if (flag.front()){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
		flag.pop();
	}



	return 0;
}