#include<iostream>
using namespace std;
int main(){
  int N,m;
  cin>>N;
  while(N--){
    int B,C=0,i=0;
    bool f=true;
    cin>>B;
    while(++i<10){
      cin>>m;
      if(B<m){
	if(B<C&&C<m)C=m;
	else B=m;
      }else if(C<m){
	C=m;
      }else{
	f=false;break;
      }
    }
    cout<<(f?"YES":"NO")<<endl;
  }
  return 0;
}