#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

int v[20];

bool dfs(const int cur, const int lv, const int rv) {
  bool ret = false;
  if (cur == 10) return true;
  // left
  if (v[cur] > lv) ret |= dfs(cur+1, v[cur], rv);
  // right
  if (v[cur] > rv) ret |= dfs(cur+1, lv, v[cur]);
  return ret;
}

int solve() {
  return dfs(0, 0, 0);
}

int main() {
  int N;
  cin >> N;
  while (N--) {
    for (int i = 0; i < 10; ++i)
      cin >> v[i];
    printf("%s\n", solve() ? "YES" : "NO");
  }
  return 0;
}