#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int b[10],z,x,n,i;
  cin >> n;
  for (n;n>0;n--) {
	  cin >> b[0] >> b[1] >> b[2] >> b[3] >> b[4] >> b[5] >> b[6] >> b[7] >> b[8] >> b[9];
      z=0; x=0;
	  for (i=0;i<10;i++) {
		  if (b[i]<x && b[i]<z) { i=20; break; }
		  if (z>x) { if (b[i]<z) x=b[i]; else z=b[i];} 
		  else {if (b[i]<x) z=b[i]; else x=b[i];} 
		   
	  }
	  if (i<20) cout << "YES" << endl; else cout << "NO" << endl;
  }
 return 0;
  }