-- Ball
main = getContents >>= putStr . solve

solve :: String -> String
-- solve = unlines . map (que [0] [0] . map read . words) . tail . lines
solve = unlines . map (tellYesNo . dfs 0 0 . map read . words) . tail . lines

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"