let n=read_int()open List;;let rec p=function|(_,_,[])->true|(x::a,[],z::c)when x<z->p(z::a,[],c)||p(x::a,[z],c)|(x::a,[],z::c)when x>=z->p(x::a,[z],c)|(x::a,y::b,z::c)when x>=z&&y<z->p(x::a,z::b,c)|(x::a,y::b,z::c)when x<z&&y>=z->p(z::a,y::b,c)|(x::a,y::b,z::c)when x<z&&y<z->p(z::a,y::b,c)||p(x::a,z::b,c)|_->false;;let rec q i=if i<n then let l=map int_of_string(Str.split(Str.regexp" ")(read_line()))in q(print_endline(if p([hd l],[],tl l)then"YES"else"NO");i+1);;q 0