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

int N;
int data[1000][10];
bool ans;

bool solve(int num) {
  stack<int> b, c;
  b.push(data[num][0]);
  for (int i = 1; i < 10; i++) {
    if (c.empty()) {
      int bt = b.top();
      (data[num][i] > bt ? b : c).push(data[num][i]);
    }
    else {
      int bt = b.top(), ct = c.top();
      if (data[num][i] > bt && data[num][i] > ct) (bt > ct ? b : c).push(data[num][i]);
      else if (data[num][i] > bt) b.push(data[num][i]);
      else if (data[num][i] > ct) c.push(data[num][i]);
      else return false;
    }
  }
  return true;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> data[i][j];
    }
  }

  for (int i = 0; i < N; i++) {
    ans = solve(i);
    cout << (ans ? "YES" : "NO") << endl;
  }


  return 0;
}