#include <cstdio>


int balls[12];

bool DFS(int cur,int left,int right){
    if (cur > 10) return true;
    auto val=balls[cur];
    return (val>left&&DFS(cur+1,val,right))||(val>right&&DFS(cur+1,left,val));
}

int main(){

    int N;
    scanf("%d",&N);

    for(int i=0;i<N;i++){
        for(int i=1;i<=10;i++) scanf("%d",balls+i);
        if (DFS(1,0,0)) puts("YES");
        else puts("NO");
    }

    return 0;
}
