{-# OPTIONS_GHC -O3 -fexpose-all-unfoldings -fdicts-cheap -fdicts-cheap #-}

import Data.List (foldl',delete)
import Control.Monad (replicateM)
import qualified Data.ByteString.Char8 as C

main = do
  n <- readLn
  s <- replicateM n C.getLine
  let xs = foldl test [] s
  putStrLn $ C.unpack $ C.unwords xs

test :: [C.ByteString] -> C.ByteString -> [C.ByteString]
test xs s
  | s == (C.pack "deleteFirst")  = tail xs
  | s == (C.pack "deleteLast")   = init xs
  | 'i' `elem` (C.unpack s)      = x : xs
  | otherwise         = delete x xs
  where
    x = (C.words s) !! 1