#include <iostream>

using namespace std;

int num[10];
bool test(int l_num, int r_num, int i) {
  if (i >= 10) return true;
  if (num[i] > l_num && num[i] > r_num) return test(num[i], r_num, i+1) || test(l_num, num[i], i+1);
  if (num[i] > l_num) return test(num[i], r_num, i+1);
  if (num[i] > r_num) return test(l_num, num[i], i+1);
  return false;
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> num[j];
    }
    if (test(0, 0, 0)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }

  return 0;
}