#include<cstdio>
#include<cstring>
int in[12],a[12],b[12];
int dfs(int *a, int cur_a, int *b, int cur_b, int cur)
{
    if(cur == 10) return 1;
    int yes = 0;
    if(cur_a < 9 && (!cur_a || in[cur] > a[cur_a-1])){
        a[cur_a] = in[cur];
        if(dfs(a,cur_a+1,b,cur_b,cur+1)) return 1;
    }
    if(cur_b < 9 && (!cur_b || in[cur] > b[cur_b-1])){
        b[cur_a] = in[cur];
        if(dfs(a,cur_a,b,cur_b+1,cur+1)) return 1;
    }
    return 0;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--){
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i = 0; i < 10; i++)
            scanf("%d",&in[i]);
        if(dfs(a,0,b,0,0)) printf("YES\n");
        else printf("NO\n");
    }
}