#include <iostream>
using namespace std;

int main() {
	int n1=0,n2=0,temp,num;
	bool flg=true;
	cin>>num;
	while(num--){
		for(int i=0;i<10;i++){
			cin>>temp;
			if(temp>n1) n1=temp;
			else if(temp>n2) n2=temp;
			else flg=false;
		} n1=0;n2=0;
		if(flg) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}	return 0;
}