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

int main(){
  int n;
  cin >> n;
  for(int i=0; i<n; i++){
    int j, tmp, b=0, c=0;
    for(j=0; j<10; j++){
      cin>>tmp;
      if(b>=c && b<tmp){b=tmp; continue;}
      else if(b>=c && c<tmp){c=tmp; continue;}
      else if(b<c && c<tmp){c=tmp; continue;}
      else if(b<c && b<tmp){b=tmp; continue;}
      break;
    }
    if(j==10) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}