#include <iostream>

using namespace std;

bool all_dropped_between(bool* dropped, int lower, int upper){
  if (lower == 0)
    return all_dropped_between(dropped, 1, upper);
  if (lower == upper - 1)
    return true;
  else
    return dropped[lower - 1] && all_dropped_between(dropped, lower + 1, upper);
}

int main(){
  int n;
  bool dropped[10];

  cin >> n;
  while(n--){
    for(int i=0; i<10; i++){
      dropped[i] = false;
    }

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

    for(int i=0; i<10; i++){
      dropped[a[i] - 1] = true;

      if(b < a[i] && c < a[i]){
        if(b < c)
          c = a[i];
        else
          b = a[i];
      }
      else if(b < a[i]){
        if(!all_dropped_between(dropped, b, a[i])){
          cout << "NO" << endl;
          break;
        }
        else
          b = a[i];
      }
      else if(c < a[i]){
        if(!all_dropped_between(dropped, c, a[i])){
          cout << "NO" << endl;
          break;
        }
        else
          c = a[i];
      }

      if(i == 9)
        cout << "YES" << endl;
    }
  }
}