import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BC
import Data.List(foldl', delete)
import Control.Monad

main :: IO ()
main = BC.getContents >>= (\(x:xs) -> BC.putStr x >> mapM_ (\x -> putChar ' ' >> BC.putStr x) xs >> putChar '\n').V.toList.solve.tail.BC.lines

solve :: [BC.ByteString] -> V.Vector BC.ByteString
solve = foldl' solve' (V.fromList [])
    where solve' xs str   = let
                             n      = BC.head $ BC.drop 6 str
                             c      = BC.head str
                             [_, x] = BC.words str
                            in solve'' n c x xs
          solve'' _ 'i' x  = V.cons x
          solve'' 'F' _  _ = V.tail
          solve'' 'L' _  _ = V.init
          solve'' _  _  x  = V.fromList.delete x.V.toList