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

int main(){
  int n;
  cin>>n;
  for(int k=0;k<n;k++){
    vector<int> a(10);
    for(int i=0;i<10;i++)cin>>a[i];
    int x=a[0];
    int y=0;
    int fl=1;
    for(int i=1;i<10;i++){
      if(x>a[i]&&y>a[i]){
        fl=0;
        cout<<"NO"<<endl;
        break;
      }
      if(x>=y){
        if(x<a[i]){
          x=a[i];
        }else{
          y=a[i];
        }
      }else{
        if(y<a[i]){
          y=a[i];
        }else{
          x=a[i];
        }
      }
    }
    if(fl)cout<<"YES"<<endl;
  }
}

