let () =
  let f pair n = match pair with
    | ([], lst2) -> ([n], lst2)
    | (lst1, []) -> if List.hd lst1 < n then (n :: lst1, []) else (lst1, [n])
    | (lst1, lst2) ->
      let b = List.hd lst1 > List.hd lst2 in 
      if b && List.hd lst1 < n then (n :: lst1, lst2)
      else if List.hd lst2 < n then (lst1, n :: lst2)
      else if List.hd lst1 < n then (n :: lst1, lst2)
      else raise Not_found in
  Scanf.scanf "%d\n" @@ fun x ->
  for i = 0 to x - 1 do
    let arr = Array.init 10 @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
    Printf.printf "%s\n"
    (try        
       let _,_ = List.fold_left f ([], []) (Array.to_list arr) in "YES"
     with Not_found -> "NO")
  done
