#include<iostream>
using namespace std;
int const N=10;
int src[N];
int a[N+1], b[N+1];//a存放左边的球，b存放右边
int aindex;//记录左边有多少球
int bindex;//右边有多少球
int ans;//标记是否能找到

void dfs(int i){//dir 标记球放在哪一边
	if (i == N){ ans = 1; return; }
	//球i放在左边
	if (src[i]>=a[aindex]){
		a[++aindex] = src[i];
		dfs(i+1);
		aindex--;
	}
	//球放在左边
	if (src[i] >= b[bindex]){
		b[bindex] = src[i];
		dfs(i + 1);
		bindex--;
	}
	return;
}
int main(){
	int n;
	cin >> n;
	while (n--){
		ans = 0;
		aindex = 0; bindex = 0;
		a[aindex] = -9999; b[bindex] = -9999;
		for (int i = 0; i < N; i++){
			cin >> src[i];
		}
		dfs(0);
		if (ans)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}


