ans' [] _ _ = "YES"
ans' (i:is) [] [] = ans' is [i] []
ans' (i:is) (a:as) [] =
  if i > a
  then ans' is (a:as) [i]
  else ans' is (a:as) [i]

ans' (i:is) (a:as) (b:bs)
  | i > a && a > b = ans' is (i:a:as) (b:bs)
  | a > i && i > b = ans' is (a:as) (i:b:bs)
  | a > b && b > i = "NO"
  | otherwise      = ans' (i:is) (b:bs) (a:as)
  
ans i = ans' i [] []

main = do
  _ <- getLine
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = map ans i
  mapM_ putStrLn o
  