#include <iostream>
using namespace std;
int main() {
  bool f;
  int n, b, c, p;
  cin >> n;
  while (n--) {
    b = c = 0;
    f = true;
    for (int i = 0; i < 10; i++) {
      cin >> p;
      if (p < b && p < c) f = false;
      else if (p > b) b = p;
      else if (p > c) c = p;
      else f = false;
    }
    cout << (f ? "YES" : "NO") << endl;
  }
}