#include <iostream>

using namespace std;

int data[10];

int scan() {
  int r = 0;
  for (int i = 0; i < 9; i++)
    if (data[i] > data[i + 1]) r++;
  return r;
}

int main()
{
  int n, limit;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      cin >> data[j];
    if (scan() > 2)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }

  return 0;
}