#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int d[11];
bool ans=false;
bool rec(int i,int a,int b){
  //cout<<"ball["<<i<<"]"<<d[i]<<" a:"<<a<<" b:"<<b<<endl;
  if(10==i)ans=true;
  if(a<d[i]){
    a=d[i];
    rec(i+1,a,b);
  }
  else if(b<d[i]){
    b=d[i];
    rec(i+1,a,b);
  }
  else return false;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    ans=false;
    for(int j=0;j<10;j++){
      cin>>d[j];
    }
    //    cout<<(rec(0,0,0)?"YES":"No")<<endl;
    rec(0,0,0);

    cout<<(ans?"YES":"NO")<<endl;
  }
  return 0;
}