#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int d[10];
bool solve(){
  int a=0;
  int b=0;
  for(int i=0;i<10;i++){
    if(a<d[i]){a=d[i];continue;}
    else if(b<d[i]){b=d[i];continue;}
    else return false;
  }
  return true;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>d[j];
    }
    cout<<(solve()?"YES":"No")<<endl;
  }
  return 0;
}