-- Ball
import Control.Monad

main = readLn
  >>= (\ n -> replicateM n getLine)
--   >>= mapM solve . map (map read . words)
  >>= putStr . unlines . map(tellYesNo . dfs 0 0 . map read . 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"