#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
  int ball[11],n,a[11],b[11];
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> ball[j];
    }
    int a_num,b_num;
    a_num = b_num = 0;
    for(int j=0;j<10;j++){
      if(j == 0){
	a[a_num] = ball[j];
	a_num++;
      }else if(ball[j]>a[a_num-1] || ball[j]>b[b_num-1]){
	// bの方が差が小さいとき
	if(ball[j]-a[a_num-1] > ball[j]-b[b_num-1]){
	  b[b_num] = ball[j];
	  b_num++;
	}else {
	  a[a_num] = ball[j];
	  a_num++;
	}
      }
    }
    if(a_num+b_num==10)cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}