#include<iostream>
using namespace std;

int a[10];
bool ans=false;
int siwake(int cun,int b,int c){
	if(cun == 10){ans=true;}
	if(a[cun]>b){siwake(cun+1,a[cun],c);}
	if(a[cun]>c){siwake(cun+1,b,a[cun]);}
	return 0;
}

int main(){
	int i,z,zc;
	cin>>z;
	for(zc=0;zc!=z;zc++){
		for(i=0;i!=10;i++){cin>>a[i];}
		siwake(0,0,0);
		if(ans==true){cout<<"YES"<<endl;
			ans=false;
		}
		else{cout<<"NO"<<endl;}
	}
}

