#include<cstdio>
const int maxn = 15;
int n,arr[maxn];
int main(){
    scanf("%d",&n);
    while(n--){
        for(int i = 0;i < 10;++i)scanf("%d",&arr[i]);
        int b = 0,c = 0,flag = 1;
        for(int i = 0;i < 10;++i){
            if(b>arr[i]&&c>arr[i]){
                flag = 0;
                break;
            }else if(b<arr[i] && c<arr[i]){
                if(b<c)c = arr[i];
                else b = arr[i];
            }else if(b < arr[i]){
                b = arr[i];
            }else c = arr[i];
        }
        if(flag)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
