#include <bits/stdc++.h>
using namespace std;

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

  for(int i=0; i<N; i++){
    vector<int> balls(10);
    for(int j=0; j<10; j++) cin >> balls[j];

    priority_queue<int> A, B;
    A.push(0); B.push(0);

    bool flag = true;
    for(int j=0; j<10; j++){
      if(A.top() > balls[j] && B.top() > balls[j]){
        if(flag) cout << "NO" << endl; 
        flag = false;
      } else if (A.top() < balls[j] && B.top() > balls[j]){
        A.push(balls[j]);
      } else if (A.top() > balls[j] && B.top() < balls[j]){
        B.push(balls[j]);
      } else {
        if(A.top() > B.top()){
          A.push(balls[j]);
        } else {
          B.push(balls[j]);
        }
      }
    }

    if(flag) cout << "YES" << endl;
  }
}
  
  
