import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.List.Split
import Data.Char
import Data.Ord
import Data.Array.IO

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

f s = f' 0 0 s
  where
    f' _ _ [] = True
    f' l r (a:as)
      | min l r > a = False
      | max l r < a = f' a (min l r) as
      | otherwise = f' a (max l r) as

main = getInt >>= flip replicateM getInts >>= mapM_ (putStrLn . cond "YES" "NO" . f)