import Control.Applicative
import Control.Monad
import Data.List

doublyList :: [String] -> [String] -> [String]
doublyList xs (c : n)
  | c == "insert" = xs `seq` (head n) : xs
  | c == "delete" = xs `seq` delete (head n) xs
  | c == "deleteFirst" = xs `seq` tail xs
  | c == "deleteLast"  = xs `seq` init xs

main :: IO ()
main = do
  n <- readLn
  loop n []
    where
      loop 0 xs = do
        putStrLn $ unwords xs
      loop i xs = do
        cmd <- words <$> getLine
        loop (i - 1) (doublyList xs cmd)

