#include <iostream>

using namespace std;

int main(){
  int n, count;
  int ball_list[10];
  int max_val;
  bool flag;

  cin >> n;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      cin >> ball_list[j];
    }

    flag = true;
    for(int j = 0; j < 10; j++){
      count = 0;
      max_val = ball_list[j];
      for(int k = j; k >= 0; k--){
        if(max_val < ball_list[k]){
          max_val = ball_list[k];
          count++;
        }
      }

      if(count >= 2){
        flag = false;
      }
    }
    if(flag){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}