#include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  while(N--){
    int B=0,C=0,i=0,b[10];
    bool f=true;
    cin>>b[0]>>b[1]>>b[2]>>b[3]>>b[4]>>b[5]>>b[6]>>b[7]>>b[8]>>b[9];
    while(i<10){
      cout << b[i] << endl;
      if(B<b[i]){
	if(B<C&&C<b[i])C=b[i];
	else B=b[i];
      }else if(C<b[i]){
	C=b[i];
      }else{
	f=false;break;
      }
      i++;
    }
    cout<<(f?"YES":"NO")<<endl;
  }
  return 0;
}