#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int x[15],l[15],r[15];

bool dfs(int i,int j,int k){
    if(i>=10)return true;

    if(x[i]>l[j-1]){
        l[j]=x[i];
        return dfs(i+1,j+1,k);
    }
    if(x[i]>r[k-1]){
        r[k]=x[i];
        return dfs(i+1,j,k+1);
    }
    return false;
}


int main(){
int t;
scanf("%d",&t);
while(t--){
    for(int i=1;i<=10;i++)scanf("%d",&x[i]);
    if(dfs(1,0,0))printf("YES\n");
    else printf("NO\n");
}
    return 0;
}