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

doublyList :: [String] -> [[String]] -> [String]
doublyList xs ys = foldl f xs ys
  where
    f xs (cmd : n)
      | cmd == "insert" = (head n) : xs
      | cmd == "delete" = delete (head n) xs
      | cmd == "deleteFirst" = tail xs
      | cmd == "deleteLast"  = init xs

main :: IO ()
main = do
  n  <- readLn
  xs <- map words <$> replicateM n getLine
  putStrLn $ unwords $ doublyList [] xs

