#include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#define min(a,b)    (((a) < (b)) ? (a) : (b))
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define abs(x)    ((x) < 0 ? -(x) : (x))
#define INF 0x3f3f3f3f
#define delta 0.85
#define eps 1e-3
#define PI 3.14159265358979323846
using namespace std;
int A[10], B[10], C[10];

bool dfs(int p, int p1, int p2){
	if(p == 10) return 1;
	if(p1 == 0 || (p1 > 0 && A[p] > B[p1 - 1])){
		B[p1] = A[p];
		if(dfs(p + 1, p1 + 1, p2)) return 1;
	}
	if(p2 == 0 || (p2 > 0 && A[p] > C[p2 - 1])){
		C[p2] = A[p];
		if(dfs(p + 1, p1, p2 + 1)) return 1;
	}
	return 0;
}

int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		for(int i = 0; i < 10; i++) scanf("%d", A + i);
		printf(dfs(0, 0, 0) ? "YES\n" : "NO\n");
	}
	return 0;
}
