#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int cs = 0 ; cs < n ; cs++){
    int A[10];
    for(int i = 0 ; i < 10 ; i++) cin >> A[i];

    int B = 0, C = 0;
    bool flag = 1;
    
    for(int i = 0 ; i < 10 ; i++){
      if(A[i] > B) B = A[i];
      else if(A[i] > C) C = A[i];
      else flag = 0;
      
      if(B < C) swap(B, C);
    }
    
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}