let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let order_p l =
  let rec doit = function
    | (_, _, []) -> true
    | ((x::xs' as xs), [], z::zs') when x < z -> doit (z::xs', [], zs') || doit (xs, [z], zs')
    | ((x::_ as xs), [], z::zs') when x >= z -> doit (xs, [z], zs')
    | ((x::_ as xs), y::ys', z::zs') when x >= z && y < z -> doit (xs, z::ys', zs')
    | (x::xs', (y::_ as ys), z::zs') when x < z && y >= z -> doit (z::xs', ys, zs')
    | ((x::xs' as xs), (y::ys' as ys), z::zs') when x < z && y < z -> doit (z::xs', ys, zs') || doit (xs, z::ys', zs')
    | _ -> false in
  doit ([List.hd l], [], List.tl l)

let () =
  let n = read_int () in
  let rec doit i =
    if i < n then begin
      let l = List.map int_of_string (split (read_line ()) ' ') in
      print_endline (if order_p l then "YES" else "NO");
      doit (i + 1)
    end in
  doit 0