#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,s,right=20,left=20,ans=0,d;
	cin>>n;
	for(int p=0;p<n;p++){
		ans=0;
		right=0;
		left=0;
		for(int q=0;q<10;q++){
			//cout<<right<<"   "<<left<<endl;
			if(right>left){//rightのほうが必ず小さい
				d=right;
				right=left;
				left=d;
			}
			cin>>s;
			if(s>left){
				left=s;
			}else if(s<right){
				ans=2;
				right=s;
			}else{
				right=s;
			}
		}
		if(ans==2){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		}
	}
}
