#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

int ball[12];
int n;

bool dfs(int i,int b,int c){
    if(i==11) return true;
    if(ball[i]>b){
        if(dfs(i+1,ball[i],c)) return true;
    }
    if(ball[i]>c){
        if(dfs(i+1,b,ball[i])) return true;
    }
    return false;
}

void solve(){
    int l=0,r=0;
    for(int i=1;i<=10;i++){
        if(ball[i]>l&&ball[i]>r){
            if(l>r) l=ball[i];
            else r=ball[i];
        }
        else{
            if(ball[i]<l&&ball[i]<r){
                printf("NO\n"); return;
            }
            else{
                if(ball[i]>r) r=ball[i];
                else l=ball[i];
            }

        }
    }
    printf("YES\n");
}


int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=10;j++)
            scanf("%d",&ball[j]);
        solve();
    }
    return 0;
}

