#include <cstdio>

int B[10];
int C[10];
int ball[10];
int res = 0;

void solve(int i, int bi, int ci) {
  if (i == 10) {
    res = 1;
    return;
  }

  if (bi == 0) {
    B[bi] = ball[i];
    solve(++i, 1, ci);
    i--;
    B[bi] = 0;
  } else {
    if (ball[i] > B[bi-1]) {
      B[bi] = ball[i];
      solve(++i, ++bi, ci);
      B[bi] = 0;
      i--;
      bi--;
    }
  }

  if (ci == 0) {
    C[ci] = ball[i];
    solve(++i, bi, 1);
  } else {
    if (ball[i] > C[ci-1]) {
      C[ci] = ball[i];
      solve(++i, bi, ++ci);
    }
  }

}

int main() {
  int i,j;
  scanf("%d", &i);
  while(i) {
    for (j=0;j<10;j++)
      scanf("%d", &ball[j]);
    solve(0,0,0);
    if (res == 1) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
    i--;
    res = 0;
  }
  return 0;
}


