#include <bits/stdc++.h>
using namespace std;

int inp[10];
int n;
bool canbe = false;

void dfs(int b, int c, int depth) {
  if (depth >= 10) {
    canbe = true; return;
  }
  if (inp[depth] < b && inp[depth] < c) return;
  if (inp[depth] > b) dfs(inp[depth], c, depth+1);
  if (inp[depth] > c) dfs(b, inp[depth], depth+1);
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    canbe = false;
    for (int j = 0; j < 10; j++) cin >> inp[j];
    dfs(0,0,0);
    cout << (canbe ? "YES": "NO") << endl;
  }

  return 0;
}