#include <iostream>
using namespace std;

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