import Control.Monad

nyan :: Int -> Int -> [Int] -> Bool
nyan _ _ [] = True
nyan a b (x:xs)
    | a < x && b < x = nyan x b xs || nyan a x xs
    | a < x          = nyan x b xs
    | b < x          = nyan a x xs
    | otherwise      = False

solve :: [Int] -> IO ()
solve = putStrLn . (\ x -> if x then "YES" else "NO") . nyan 0 0

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