#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int n;
	cin>>n;
	vector<int> a(10);
	for(int i=0;i<n;i++){
		queue<int>b,c,d;
for(int j=0;j<10;j++){
	cin>>a[j];
}
for(int j=0;j<10;j++){
	if(b.empty()){
		b.push(a[j]);
	}else if(b.back()<a[j]){
		b.push(a[j]);
	}else if(c.empty()){
		c.push(a[j]);
	}else if(c.back()<a[j]){
		c.push(a[j]);
	}else{
		d.push(a[j]);
	}

}
if(d.empty()){
	cout<<"YES"<<endl;
}else{
	cout<<"NO"<<endl;
}
	}
	return 0;
}