#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int T;
int t[10];

bool solve(){
  int left=0,right=0;
  rep(i,10){
    if(t[i] < left && t[i] < right) return false;
    if(t[i] > left){
      if(t[i] > right && left < right){
        right = t[i];
      }
      else{
        left = t[i];
      }
    }
    else{
      right = t[i];
    }
  }
  return true;
}

int main(){
  cin>>T;
  while(T--){
    rep(i,10){
      cin>>t[i];
    }
    cout<<(solve() ? "YES" : "NO")<<endl;
  }
}