#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD
 
int main(){
  int n;
  cin>>n;
  while(n--){
    bool used[10];
    REP(i,10)used[i]=false;
    int left=-1,right=-1;
    bool flag = true;
    REP(i,10){
      int x;
      cin>>x;
      --x;
      if(x<left && x<right){
        flag = false;
        break;
      }else if(x<left && x>right){
        right = x;
        used[x] = true;
      }else if(x>left && x<right){
        left = x;
        used[x] = true;
      }else{
        if(right>left){
          right = x;
          used[x] = true;
        }else{
          left = x;
          used[x] = true;
        }
      }
    }
    if(flag){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}