#include<iostream>
#include<algorithm>
using namespace std;

int main(){

  int n,m;

  cin >> n;

  for(int i=0;i<n;i++){

    int a[100],b[100] = {0},c[100] = {0} ,s = 0,t = 0,x,y,count = 0;

    for(int j=0;j<10;j++){

      cin >> m;

      if(j == 0){
	b[s] = m;
	s++;
      }

      if(j == 1){
	c[t] = m;
	t++;
      }

      if(m > b[s-1] && m < c[t-1]){
	b[s] = m;
	s++;
      }

      else if(m > c[t-1] && m < b[s-1]){
	c[t] = m;
	t++;
      }

      else if(b[s-1] > c[t-1] && m > b[s-1]){
	b[s] = m;
	s++;
      }

      else if(c[t-1] > b[s-1] && m > c[t-1]){
	c[t] = m;
	t++;
      }

      else if(m < c[t-1] && m < b[s-1])	count = 1;
    }

    if(count == 1) cout << "NO" << endl;
    else cout << "YES" << endl;

  }
}
  