#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<list>


using namespace std;

#define FOR(x) for(int i = 0; i < x; i++)

stack<short> left, right;
short a[10], n, j;

bool solve(short c, bool judge){
	if(c == 10) return true;
	if(left.top() < a[c]){
		left.push(a[c]);
		if(solve(c + 1, true)) return true;
	}
	if(right.top() < a[c]){
		right.push(a[c]);
		if(solve(c + 1, false)) return true;
	}
	if(judge) left.pop();
	else right.pop();
	return false;
}

int main(){
	scanf("%d", &n);
	FOR(n){
		left.push(0);
		right.push(0);
		for(j = 0; j < 10; j++)
			scanf("%d", &a[j]);
		if(solve(0, true)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}