#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>

using namespace std;

int A[10];
int n;

bool dfs(int, int, int);

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++)
  {
  for(int i = 0; i < 10; i++)
    scanf("%d", &A[i]);

    cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
  }
  return 0;
}

bool dfs(int ai, int b, int c)
{
  if(ai == 10)
    return true;
  int bb = b;
  int bc = c;
  bool ans = false;
  if(A[ai] > b)
  {
    b = A[ai];
    //cout << b  << " into B" << ai << endl;
    ans = ans || dfs(ai + 1, b, c);
    b = bb;
  }
  if(A[ai] > c)
  {
    c = A[ai];
    //cout << b  << " into C" << ai << endl;
    ans = ans || dfs(ai + 1, b, c);
    c = bc;
  }
  return ans;
}