import Data.List (delete)

main = do
  n <- readLn
  main2 n []

main2 n xs = do
  if n == 0
  then do
    putStr $ unwords xs
  else do
    s <- getLine
    let xs' = test s xs
    main2 (n-1) xs'

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