#include<cstdio>
int N, a[15];
void solve()
{
    int x = a[0], y = 0;
    for(int i = 1; i < 10; i++){
        if(a[i] > x && a[i] > y){
            if(a[i] - x >= a[i] - y)
                y = a[i];
            else
                x = a[i];
        }
        else if(a[i] > x)
            x = a[i];
        else if(a[i] > y)
            y = a[i];
        else{
            printf("NO\n");
            return;
        }
    }
    printf("YES\n");
}
int main()
{
    scanf("%d", &N);
    while(N--){
        for(int i = 0; i < 10; i++)
            scanf("%d", &a[i]);
        solve();
    }
    return 0;
}

