//???1601-2 ????±????(616342287) 12:28:09
#include <iostream>
#include <fstream>
#include <stack>
#include <vector>
#include <cstring>
using namespace std;
int a[11];
int b[11];
int c[11];
int flag;
void dfs(int x,int y,int z)
{
  if(x==10)
  {
    flag=1;
    return;
  }
  if(a[x]<b[y]&&a[x]<c[z])
      return;
  if(a[x]>b[y])
  {
      b[y+1]=a[x];
      dfs(x+1,y+1,z);
      b[y+1]=0; 
  }
  if(a[x]>c[z])
  {
      c[z+1]=a[x];
      dfs(x+1,y,z+1);
      c[z+1]=0; 
  }
}
int main()
{
//  freopen("3.txt","r",stdin);
  int n;
  cin >> n;
  while(n--)
  {
  flag=0;
  memset(b,0,sizeof(b));
  memset(c,0,sizeof(c));
  for(int i=0;i<10;i++)
      cin >> a[i];
  dfs(0,0,0);
  if(flag)
      cout << "YES" << endl;
  else
      cout << "NO" << endl;
  }
  return 0;
}