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

bool ok;
int a[10];

void dfs(int i, int left, int right) {
  if(i == 10) {
    ok = true;
    return;
  }
  if(left < a[i]) dfs(i + 1, a[i], right);
  if(right < a[i]) dfs(i + 1, left, a[i]);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < 10; ++j) {
      cin >> a[j];
    }

    ok = false;
    dfs(0, 0, 0);
    if(ok) cout << "YES\n";
    else cout << "NO\n";
  }
}
