#include <iostream>
#include <stack>
using namespace std;

bool solve(int ball[10]){
  stack<int> b, c;
  b.push(ball[0]);
  c.push(0);
  for(int i = 1; i < 10; i++){
    if(ball[i] < b.top() && ball[i] < c.top()) return false;
    if(b.top() > c.top()){
      if(ball[i] > b.top()) b.push(ball[i]);
      else c.push(ball[i]);
    }
    else{
      if(ball[i] > c.top()) c.push(ball[i]);
      else b.push(ball[i]);
    }
  }
  return true;
}

int main(){
  int N;
  cin >> N;

  int ball[10];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 10; j++){
      cin >> ball[j];
    }
    if(solve(ball)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}
