#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

int main(){
  int n,a,b,c,i;
	bool flag;
	cin>>n;
	for(;n>0;n--){
		a = b = 0;
		flag = true;
		for(i=0;i<10;i++){
			cin>>c;
			if(a >= b && c > a)
				a = c;
			else if(c > b)
				b = c;
			else
				flag = false;
		}
		if(flag)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
  return 0;
}