import qualified Data.ByteString.Lazy.Char8 as C
import Data.List

solve :: [C.ByteString] -> [[C.ByteString]] -> C.ByteString
solve s [] = C.unwords s
solve s	([a]:xs)
  | C.length a > 6 && C.index a 6 == 'F' = solve (tail s) xs
  | C.length a > 6 && C.index a 6 == 'L' = solve (init s) xs
solve s ([a,b]:xs)
  | C.index a 0 == 'i' = solve (b:s) xs
solve s ([_,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

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