#include <stdio.h>

int main(void){
    int next;
    int n;
    int atop,btop;
    
    scanf("%d", &n);
    for (int i=0; i<n; i++){
        atop = btop = 0;
        for (int j=0; j<10; j++){
            scanf("%d", &next);
            if (next<atop && next<btop){
                printf("NO\n");
                break;
            }
            else if (next<atop && next>btop) btop = next;
            else if (next>atop && next<btop) atop = next;
            else (atop<btop?btop:atop) = next;
            if (j==9) printf("YES\n");
        }
    }
    
    return 0;
}