#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int d=0;d<n;d++){
	int a[10]={},b[10]={},c[10]={};
	for(int i=0;i<10;i++){
		cin>>a[i];
	}
	int j=0,k=0;
	for(int i=0;i<10;i++){
		if(b[j]<a[i]){
			b[j+1]=a[i];
			j++;
		}
		else if(c[k]<a[i]){
			c[k+1]=a[i];
			k++;
		}
		else{
			cout<<"NO"<<endl;
			goto age;;
		}
	}
	cout<<"YES"<<endl;
	age:;
}
	return 0;
}

