#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[20];
int b[20],c[20];
int n;
bool flag;
void dfs(int i,int j,int k)
{
    if(i == 10)
    {
        flag = true;
        return ;
    }
    if(flag == true)
        return ;
    if(a[i] > c[j - 1]){
       /* printf("游街、?\n");
        printf("a[i] = %d\n",a[i]);
        printf("c[j - 1] = %d\n",c[j - 1]);*/
        c[j] = a[i];
       /* printf("c[j] = %d\n",c[j]);
        printf("j = %d\n",j);
        printf("i = %d\n",i);*/
        dfs(i + 1,j + 1,k);
        memset(c,0,sizeof(c));
    }
    printf("\n\n\n\n");
    if(a[i] > b[k - 1]){
        //printf("a[i] = %d\n",a[i]);
       // printf("b[k - 1] = %d\n",b[k - 1]);
        b[k] = a[i];
       /* printf("b[k] = %d\n",b[k]);
        printf("k = %d\n",k);
        printf("i = %d\n",i);*/
        dfs(i + 1,j,k + 1);
    }
   // printf("OKOKOK\n\n\n\n");
    return ;
}
int main()
{
    scanf("%d",&n);
    while(n --)
    {
        for(int i = 0; i < 10; i++)
            scanf("%d",&a[i]);
        flag = false;
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));

        dfs(0 , 1, 1);
        //printf("b[1] = %d\n",b[1]);

        if(flag == true)
            printf("YES\n");
        else
            printf("NO\n");
       /* for(int i = 0; i <= 10; i++)
            printf("%d ",c[i]);
        printf("\n");
        for(int i = 0; i <= 10; i++)
            printf("%d ",b[i]);
        printf("b[1] = %d\n",b[1]);*/
    }
    return 0;
}
/*
100
1 2 3 4 8 5 6 7 9 10
*/