#include <iostream>
using namespace std;

int n;
int ball[10];
int r, l;
int now;

bool dfs(int r, int l, int now);

int main(){

	cin >> n;

	for(int i=0; i<n; i++){
		r = 0;
		l = 0;
		now = 0;

		for(int j=0; j<10; j++){
			cin >> ball[j];
		}

		if(dfs(0, 0, 0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}

bool dfs(int right, int left, int now){
	if(now == 10) return true;
	if(right < ball[now]) return dfs(ball[now], left, now+1);
	if(left < ball[now]) return dfs(right, ball[now], now+1);
	return false;
}