#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;

int main(void){
  int n,N;
  vector<int> v(10);
  cin >> N;
  REP(n,N){
    int i;
    bool flg = true;
    REP(i,v.size()) cin >> v[i];
    int max = 0,min = 0;
    REP(i,v.size()){
      if(max<v[i]) max = v[i];
      else if(min<v[i]) min = v[i];
      else{
        flg = false;
        break;
      }
    }
    if(flg) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

