#include<cstdio>
#include<array>
#include<vector>
using namespace std;

array<int, 10> ary;
vector<int> lf, rt;

int main(){
	bool dfs(int );
	
	
	int n;
	scanf("%d", &n);
	for(int i  = 0; i < n; i++){
		for(int j = 0; j < 10; j++){
			int t;
			scanf("%d", &t);
			ary[j] = t;
		}
		lf.clear();
		rt.clear();
		if(dfs(0)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
} 

bool dfs(int i){
	if(i == 9){
		if(lf.size() == 0 || rt.size() == 0) return true;
		else if(ary[i] > *lf.rbegin() || ary[i] > *rt.rbegin()) return true;
		else return false;
	}
	lf.push_back(ary[i]);
	if(lf.size() == 1 || lf[lf.size() - 1] > lf[lf.size() - 2]) return dfs(i+1);
	lf.pop_back();
	rt.push_back(ary[i]);
	if(rt.size() == 1 || rt[rt.size() - 1] > rt[rt.size() - 2]) return dfs(i+1);
	return false;
}
