#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

int n,x[10];
int b,c;
char t;
bool flag=true;

int main(){
	cin>>n;
	rep(i,n){
		flag = true;
		b = c = -1;
		rep(j,10) cin>>x[j];
		rep(j,10){
			if(x[j]<min(b,c)){
				flag = false;
				break;
			}
			if(x[j]<b) c = x[j];
			else if(x[j]<c) b = x[j];
			else if(b<c) c = x[j];
			else b = x[j];
			//cout<<b<<" "<<c<<endl;
		}
		if(flag) cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}