#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
using namespace std;

int ball[10];

stack<int> b;
stack<int> c;

bool routine(int dep){
	if(dep == 10){
		return true;
	}
	bool bcheck;
	//b?????\??????
	if(b.size() == 0){
		b.push(ball[dep]);
		bcheck = routine(dep+1);
	}else{
		if(b.top() < ball[dep]){
			b.push(ball[dep]);
			bcheck = routine(dep+1);
		}else{
			bcheck = false;
		}
	}
	bool ccheck;
	if(c.size() == 0){
		c.push(ball[dep]);
		ccheck = routine(dep+1);
	}else{
		if(c.top() < ball[dep]){
			c.push(ball[dep]);
			ccheck = routine(dep+1);
		}else{
			ccheck = false;
		}
	}
	return (bcheck || ccheck);
}

void solve(){
	for(int i = 0; i < 10; i++){
		scanf("%d", &ball[i]);
	}
	printf(routine(0) ? "YES\n" : "NO\n");
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		solve();
	}
	return 0;
}