{-# LANGUAGE OverloadedStrings #-}

import Control.Applicative
import Control.Monad
import qualified Data.ByteString       as B
import qualified Data.ByteString.Char8 as B8
import Data.List

doublyList :: [B.ByteString] -> [B.ByteString] -> [B.ByteString]
doublyList xs (c : n)
  | c == "insert" = (head n) : xs
  | c == "delete" = delete (head n) xs
  | c == "deleteFirst" = tail xs
  | c == "deleteLast"  = init xs

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

