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

main :: IO ()
main = BC.getContents >>= BC.putStrLn.BC.unwords.map BC.singleton.V.toList.solve.tail.BC.lines

solve :: [BC.ByteString] -> V.Vector Char
solve = foldl' solve' (V.fromList [])
    where solve' xs str   = let
                             n = BC.length str
                             c = BC.head str
                             x = BC.last str
                            in solve'' n c x xs
          solve'' _ 'i' x = V.cons x
          solve'' 10 _  _ = V.tail
          solve'' 11 _  _ = V.init
          solve'' _  _  x = V.fromList.delete x.V.toList