#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <queue>
#include <string>
#include <map>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  for (int I = 0; I < N; I++) {
    int b = 0, c = 0;
    for (int i = 0; i < 10; i++) {
      int x;
      cin >> x;
      if (x < b)
        if (x < c) {
          cout << "NO" << endl;
          goto next;
        } else
          c = x;
      else
        b = x;
    }
    cout << "YES" << endl;
next:;
  }
  return 0;
}