#include<cstdio>
#define NUM 10
using namespace std;
bool solve(int data[NUM], int id, int l, int r){
  if(id == NUM)
    return true;
  else if(data[id] > l && data[id] > r)
    return solve(data,id+1,data[id],r) || solve(data,id+1,l,data[id]);
  else if(data[id] < l){
    if(data[id] < r)
      return false;
    else
      return solve(data,id+1,l,data[id]);
  }
  return solve(data,id+1,data[id],r);
}
int main(){
  int N;
  scanf("%d",&N);
  int data[NUM];
  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j < NUM ; j++)
      scanf("%d",&data[j]);
    if(solve(data,0,0,0))
      printf("YES\n");
    else
      printf("NO\n");
  }
}

