#include<iostream>
using namespace std;
int main(){
  int n,a[10];
  cin >>n;
  while(n--){
    int lot[50][2],r = 0,l = 0,x = 0;
    for(int i=0; i<10; i++) cin >>a[i];
    for(int i=0; i<10; i++){
      if(l<a[i] && r<a[i]){
	lot[x][0] = l;
	lot[x][1] = i;
	x++;
	l = a[i];
      }
      else if(l<a[i]) l = a[i];
      else if(r<a[i]) r = a[i];
      else{
	if(x == 0){cout <<"NO"<<endl;break;}
	x--;
	l = lot[x][0];
	i = lot[x][1];
	r = a[i];
      }
      if(i == 9) cout <<"YES"<<endl;
    }
  }
  return 0;
}