#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;

const int MAX = 10;
int ball[MAX];
int can;
int n;

void dfs(int left, int right, int num){
	if(num == 10) can = 1;
	if(can != 0) return;
	if(ball[num] > left) dfs(ball[num], right, num+1);
	if(ball[num] > right) dfs(left, ball[num], num+1);
	return;
}

int main(){
	cin >> n;
	while(n--){
		for(int i = 0; i < 10; i++)
			cin >> ball[i];
		can = 0;
		dfs(0,0,0); 
		if(can == 0) cout << "NO" << endl;
		else cout << "YES" << endl;
	}
	return 0;
} 
