import qualified Data.Vector.Unboxed as V
import Data.List(foldl', delete)
import Data.Maybe(fromJust)

main = getContents >>= putStrLn.unwords.map show.V.toList.solve.tail.lines

solve :: [String] -> V.Vector Int
solve = foldl' solve' (V.fromList [])
    where solve' xs "deleteFirst"                 = V.tail xs
          solve' xs "deleteLast"                  = V.init xs
          solve' xs ('i':'n':'s':'e':'r':'t':_:x) = V.cons (read x) xs
          solve' xs ('d':'e':'l':'e':'t':'e':_:x) = V.fromList.delete (read x) $ V.toList xs