#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int n;
  cin>>n;
  REP(i,n){
    int x[10]={};
    bool f=true;
    REP(i,10)cin>>x[i];
    stack<int> B,C;
    B.push(x[0]);
    REP(i,9){
      if(x[i+1]<B.top()){
        if(C.empty()||(x[i+1]>C.top()&&!C.empty())){
          C.push(x[i+1]);
        }else{
          f=false;
          break;
        }  
      }else B.push(x[i+1]);
    }
    cout<<(f?"YES":"NO")<<endl;
  }
  return 0;
}