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

delete' :: Eq a => a -> [a] -> [a]
delete' _ [] = []
delete' n (x : xs) | n == x    = xs
                   | otherwise = x : delete' n xs

deleteFirst :: [a] -> [a]
deleteFirst []       = []
deleteFirst (x : xs) = xs

deleteLast :: [a] -> [a]
deleteLast = init

insert' :: a -> [a] -> [a]
insert' n xs = n : xs

parseLine :: String -> [String] -> [String]
parseLine str | str == "deleteFirst"  = deleteFirst
              | str == "deleteLast"   = deleteLast
              | head strs == "insert" = insert' (strs !! 1)
              | head strs == "delete" = delete' (strs !! 1)
  where strs = words str

doing :: Int -> [String] -> IO [String]
doing n xs = do
  f <- parseLine <$> getLine
  let r = f xs
  case n of
    1 -> return r
    _ -> doing (n - 1) r

main :: IO ()
main = do
  n <- readLn
  r <- doing n []
  putStrLn $ unwords r


