let rec p x y=function|[]->true|z::_ when x>z&&y>z->false|z::r when x<z&&y>z->p z y r|z::r when x>z&&y<z->p x z r|z::r when x<z&&y<z->p x z r||p z y r|_->false;;for i=1to read_int()do print_endline(if p 0 0(List.map int_of_string(Str.split(Str.regexp" ")(read_line())))then"YES"else"NO")done