#include <stdio.h>
int a[10];
int dfs(int l,int r,int i){
  if(i==10)return 1;
  if(a[i]>l&&dfs(a[i],r,i+1))return 1;
  if(a[i]>r&&dfs(l,a[i],i+1))return 1;
  return 0;
}
int main(){
  int n;
  scanf("%d",&n);
  for(;n;n--){
    scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
    dfs(0,0,0)?printf("YES\n"):printf("NO\n");
  }
  return 0;
}