#include <bits/stdc++.h>
using namespace std;
void dfs(int, int, int);
int arr[10];
bool flag;
int main() {
  int n;
  cin >> n;
  while (n--) {
    for (int i = 0; i < 10; i++)
      cin >> arr[i];
    dfs(0, 0, 0);
    if (flag)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    flag = false;
  }
  return 0;
}

void dfs(int sta1, int sta2, int index) {
  if (index == 10) {
    flag = true;
    return;
  }
  if (sta1 < arr[index]) {
    sta1 = arr[index];
    dfs(arr[index], sta2, index + 1);
  }
  if (sta2 < arr[index]) {
    sta2 = arr[index];
    dfs(sta1, sta2, index + 1);
  }
}
