#include <iostream>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  int t;
  int i, j;
  for (i = 0; i < n; i++) {
    queue<int> q;
    for (j = 0; j < 10; j++) {
      cin >> t;
      q.push(t);
    }
    stack<int> a, b;
    a.push(q.front());
    q.pop();
    b.push(0);
    while (q.size()) {
      if (a.top() < q.front()) {
        a.push(q.front());
      } else if (b.top() < q.front()) {
        b.push(q.front());
      } else {
        cout << "NO" << endl;
        break;
      }
      q.pop();
      if (q.size() == 0) {
        cout << "YES" << endl;
      }
    }
  }
  return 0;
}

