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

using namespace std;

int main(){
  int f;
  int n;
  int in,b,c;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    f=b=c=0;
    for(int j=0;j<10;j++){
      scanf("%d",&in);
      if(!f){
	if(in<=min(b,c)){
	  f=1;
	}
	if((b>=c && b<in)||(b<c && c>in))b=in;
	else c=in;
      }
    }
    if(f)printf("NO\n");
    else printf("YES\n");
  }
}