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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    vector<int> v(10);
    for (int j = 0; j < 10; j++) {
      cin >> v.at(j);
    }
    sort(v.begin(), v.begin() + 2);
    int a = v.at(0), b = v.at(1);
    bool flag = true;
    for (int k = 2; k <= 10; k++) {
      if (v.at(k) > a) {
        if (v.at(k) < b) {
          a = v.at(k);
        } else {
          b = v.at(k);
        }
      } else {
        flag = false;
      }
    }
    if (flag)
    cout << "YES" << endl;
    else
    cout << "NO" << endl;
  }
}

