#include <bits/stdc++.h>

using namespace std;

bool flag;
int a[10], b[10], c[10];

void dfs(int ap, int bp, int cp){
  
  // cout << ap << ' ' << bp << ' ' << cp << endl;

  if(ap == 10){
    flag = true;
    return;
  }

  if(ap < 2){
    if(ap){
      b[0] = a[ap];
      dfs(ap + 1, bp + 1, cp);
      b[bp] = 0;
    }
    else{
      c[0] = a[ap];
      dfs(ap + 1, bp, cp + 1);
      c[cp] = 0;
    }
  }
  else{

    if(a[ap] > b[bp - 1]){
      b[bp] = a[ap];
      dfs(ap + 1, bp + 1, cp);
      b[bp] = 0;
    }
    
    if(a[ap] > c[cp - 1]){
      c[cp] = a[ap];
      dfs(ap + 1, bp, cp + 1);
      c[cp] = 0;
    }

  }

  return;

}

int main(){

  int n;

  cin >> n;

  for(int i = 0; i < n; ++i){
    
    flag = false;

    for(int j = 0; j < 10; ++j){
      b[j] = 0;
      c[j] = 0;
    }
    
    for(int j = 0; j < 10; ++j){
      cin >> a[j];
    }
    
    dfs(0, 0, 0);

    cout << (flag ? "YES" : "NO") << endl;

  }

}