#include<cstdio>
#define ture 1
#define false 0
using namespace std;

int s[10],l[10],r[10];

bool slove(int i,int j,int k){

for(int i=1;i<10;i++)
{
    if(s[i]<l[j]&&s[i]<r[k]){
        return false;
    }
    if(s[i]>l[j]&&s[i]<r[k]){
        l[j+1]=s[i];
        j++;
    }
    if(s[i]<l[j]&&s[i]>r[k]){
        r[k+1]=s[i];
        k++;
    }
    else{
    if(s[i]-1==l[j]){
        l[j+1]=s[i];
        j++;
    }
    else if(s[i]-1==r[k+1]){
        r[k+1]=s[i];
        k++;
    }
    else if((s[i]-l[j])<(s[i]-r[k])){
        l[j+1]=s[i];
        j++;
    }
    else {
        r[k+1]=s[i];
        k++;
    }
    }
}
return true;
}







    /*
        if(k==10)
        return ture;
        if(l[i]>s[k]&&r[j]>s[k])
        return false;
        l[i+1]=s[k];
        r[j+1]=s[k];
        if(slove(i,j+1,k+1)&&r[j]<s[k])
            {
                l[i+1]=0;
                return ture;
            }
            else if(slove(i+1,j,k+1)&&l[i]<s[k])
            {
                r[j+1]=0;
                return ture;
            }
            else
                return false;*/


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

