#include<iostream>
#include<queue>
using namespace std;
int main (){
	int n;
	cin>>n;
	queue <int > p,q;
	int a[10];
	while(n--){
		for (int i=0;i<10;i++){
			cin>>a[i];
			if(!i) p.push(a[i]);
			if(a[i]<p.back()) q.push(a[i]);
			else p.push(a[i]);
		}
		int t=q.front(),k=0;
		q.pop();
		while(!q.empty()){
			if(t>q.front()){
				k=1;
				break;
			}else {
				q.pop();
			}
		}
		if(k) cout<<"NO"<<endl;
		else cout<<"YES"<<endl; 
	}
} 
