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 (x, y) = function
    | [] -> true
    | z::_ when x > z && y > z -> false
    | z::r when x < z && y > z -> doit (z, y) r
    | z::r when x > z && y < z -> doit (x, z) r
    | z::r when x < z && y < z -> doit (x, z) r || doit (z, y) r
    | _ -> false in
  doit (0, 0) 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