#include<iostream>
using namespace std;
int ball[10];
int flag;  //1??????YES???0??????NO
void dfs(int left,int right,int depth){
  if(depth==10){ //???????????????????????§??\???????????????
    flag=1;
    return;
  }
  if(left<ball[depth])
    dfs(ball[depth],right,depth+1);
  if(right<ball[depth])
    dfs(left,ball[depth],depth+1);
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    flag=0;//????????°????????????
    for(int j=0;j<10;j++)
      cin>>ball[j];
    dfs(ball[0],0,1);//????????????????????\??????????????????
                     //3??????????????°?????±???
                     //?????????????????\?????????????????\???????????????????????§
                     //????????\?????????????????????????????????
    if(flag)
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
  return 0;
}