#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
    int N,pre,current,second_pre;
    bool NO_FLG;

    scanf("%d",&N);
    for(int i=0;i<N;i++){
        pre = -1;
        second_pre = -1;
        NO_FLG = false;
        for(int k = 0; k < 9; k++){
            scanf("%d",&current);	//????????????????????????
            if(k == 0){	//??????????????????????????´?????????????????????
                pre = current;
            }else{
                if(pre > current){	//1?????????????????????????????§????????´???,current?????????1????????????????§????
                    if(second_pre == -1){	//?°?????????°????????\?????????????§????
                        second_pre = current;
                    }else{
                        if(second_pre > current){ //2????????????????????°??????current???????????§????????´???
                            printf("NO\n");
                            NO_FLG = true;
                            break;
                        }else{	//2????????????????????°??????current??????????°?????????´???
                            second_pre = current;
                        }
                    }
                }else{ //pre < current
                	pre = current;
                }
            }
        }
        if(!NO_FLG)printf("YES\n");

    }
    return 0;
}