import Data.List

solve :: [String] -> [[String]]	-> String
solve s	[] = unwords s
solve s (["insert",a]:xs) = solve (a:s) xs
solve s (["delete",a]:xs)
  | e /= Nothing = solve (take j s ++ drop (j+1) s) xs
  | otherwise =	solve s	xs
  where e = elemIndex a s
        Just j = e
solve s (["deleteFirst"]:xs) = solve (tail s) xs
solve s (["deleteLast"]:xs) = solve (init s) xs

main = getContents >>= putStrLn . solve [] . map words . tail . lines
