#include<cstdio>
#include<iostream>

using namespace std;

int main(void){

	int N,B=0,C=0,ball,flag=0;

	cin>>N;

	for(int i=0;i<N;i++){
		B=0,C=0,flag=0;
		for(int j=0;j<10;j++){
			cin>>ball;
			if(ball>B){
				if(ball>C){
					if(C>B) C=ball;
					else B=ball;
				}
				else B=ball;
			}
			else if(ball>C){
				C=ball;
			}
			else flag=1;
		}
		if(flag==0) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

return 0;

}