-- Ball
-- import Control.Monad
--
-- main :: IO ()
-- main = readLn
--   >>= (\ n -> replicateM n getLine)
--   >>= mapM putStrLn . solve
--
-- kolve :: [String] -> String
-- solve = tellYesNo . dfs 0 0 . map (map read . words)
--
-- dfs :: Int -> Int -> [Int] -> Bool
-- dfs _ _ [] = True
-- dfs l r (x:xs)
--   | l < x && r < x = dfs x r xs || dfs l x xs
--   | l < x     = dfs x r xs
--   | r < x     = dfs l x xs
--   | otherwise = False
--
import Control.Monad

main = readLn
  >>= (\ n -> replicateM n getLine)
  >>= mapM solve . map (map read) . map words

solve :: [Int] -> IO ()
solve = putStrLn . tellYesNo . dfs 0 0

dfs :: Int -> Int -> [Int] -> Bool
dfs _ _ [] = True
dfs l r (x:xs)
  | l < x && r < x = dfs x r xs || dfs l x xs
  | l < x = dfs x r xs
  | r < x = dfs l x xs
  | otherwise = False

tellYesNo :: Bool -> String
tellYesNo b
  | b == True = "YES"
  | otherwise = "NO"