let () =
  let n = read_int () in
  let rec read = function
      0 -> ()
    | i ->
       let line = read_line ()
                  |> Str.split (Str.regexp " ")
                  |> List.map int_of_string in
       let rec insert b c = function
           [] -> true
         | hd::tl -> if List.length b = 0 || List.hd b < hd then
                       insert (hd::b) c tl
                     else if List.length c = 0 || List.hd c < hd then
                       insert b (hd::c) tl
                     else
                       false
       in print_endline (if insert [] [] line then "YES" else "NO");read (i-1)
  in read n;;