import Control.Applicative ((<$>))
import Control.Monad (replicateM, forM_)

solve :: [Int] -> [Int] -> [Int] -> String
solve [] bs cs = "YES"
solve (a:as) bb@(b:bs) cc@(c:cs)
  | a > b && a > c = if b >= c
                       then solve as (a:bb) cc
                       else solve as bb (a:cc)
  | a > b          = solve as (a:bb) cc
  | a > c          = solve as bb (a:cc)
  | otherwise      = "NO"

main = do
  n <- (read :: String -> Int) <$> getLine
  xs <-  replicateM n getLine
  let xs' = fmap words xs
      xs'' = fmap (\a -> fmap (\aa -> (read :: String -> Int) aa) a) xs' in
    do
      forM_ xs'' (\as -> putStrLn (solve as [0] [0]))