#include <cstdio>

int main(){
  int n;
  scanf("%d",&n);
  while(n--){
    int a=0,b=0,m;
    for(int i=0; i<10; i++){
      scanf("%d",&m);
      if(a<m)
	a=m;
      else if(b<m)
	b=m;
      else{
	printf("NO\n");
	while(getchar()!='\n');
	goto hoge;
      }

      if(a<b){
	int c; 
	c=a;a=b;b=c;
      }
    }
    printf("YES\n");
  hoge: ;
  }
}