#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i<k;i++)
int N;
int A[10];
bool DFS(int Aindex,int x,int y){
  if(Aindex ==10)return true;
  if(x>A[Aindex] && y>A[Aindex])return false;
  bool m=false;
  if(x<A[Aindex])m=max(m,DFS(Aindex+1,A[Aindex],y));
  if(y<A[Aindex])m=max(m,DFS(Aindex+1,x,A[Aindex]));
  return m;
}
int main(){
  cin >> N;
  string ans[2]={"NO","YES"};
  rep(i,0,N){
    rep(i,0,10){
      cin >>A[i];
    }
    cout << ans[DFS(0,0,0)]<<endl;
  }
  return 0;
}

