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

import Data.List (foldl',delete)
import Control.Monad (replicateM)

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

test xs s
  | s == "deleteFirst"  = tail xs
  | s == "deleteLast"   = init xs
  | 'i' `elem` s      = x : xs
  | otherwise         = delete x xs
  where
    x = (words s !! 1)