#include <iostream>
using namespace std;
int n;
int ball[10];
bool b1;

bool hako(int top1,int top2,int i) {
  if(i<=9) {
    if((ball[i] > top1) && (ball[i] > top2)) {
      return hako(ball[i],top2,i+1) || hako(top1,ball[i],i+1);
    }
    else if(ball[i] > top1) {
      return hako(ball[i],top2,i+1);
    }
    else if(ball[i] > top2) {
      return hako(top1,ball[i],i+1);
    }
    else
      return false;
  }
  return true;
}

int main() {
  cin >> n;
  for(int i=0;i<n;i++) {
    for(int i=0;i<10;i++) {
      cin >> ball[i];
    }
    if(b1 = hako(0,0,0),b1) printf("YES\n");
    else printf("NO\n");
  }
}