#include <iostream>

using namespace std;
const int kBalln = 10;
int ball[kBalln];

bool ExistAsceOrder(int i, int a, int b){
  if (i == kBalln)  return true;

  if (a < ball[i]) 
    {
      if(ExistAsceOrder(i+1,ball[i],b)) return true;
    }

  if (b < ball[i])
    {
      if(ExistAsceOrder(i+1,a,ball[i])) return true;
    }

  return false;
}

int main(){
  int n;

  cin >> n;
  for (int j = 0; j < n; ++j)
    {
      for (int i = 0; i < kBalln; ++i)
        {
          cin >> ball[i];
        }
      cout << (ExistAsceOrder(0,0,0)? "YES" : "NO") << endl;
    }
  return 0;
}