#include <iostream>
using namespace std;
int d[10];
int l;
int r;

bool choose(int i, bool b);

int main() {
  int n;
  cin >> n;

  for (int i=0; i<n; i++) {
    for (int j=0; j<10; j++) {
      cin >> d[j];
    }
    l = r = 0;
    if (choose(0, true)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

}

bool choose(int i, bool b) {
  int old;
  int *p;
  if (b) p = &l;
  else p = &r;
  if (d[i] > *p) {
    if (i == 9) return true;
    old = *p;
    *p = d[i];
    if (choose(i+1, true)) return true;
    if (choose(i+1, false)) return true;
    *p = old;
    return false;
  } else {
    return false;
  }
}