#include<iostream>

using namespace std;

int main(){
  int n,val,B,C;
  cin >> n;
  while(n-- >0){
    B = 0;
    C = 0;
    bool fin=false;
    for(int i=0;i<10;i++){
      cin >> val;
      if(val > B && val > C){
	if(B>=C)B=val;
	else C=val;
      }
      else if(val > B)B=val;
      else if(val > C)C=val;
      else fin=true;
    }
    if(fin) cout << "NO" << endl;
    else cout << "YES" << endl;
  }
  return 0;
}