operate2 :: Int -> Char -> String -> String
operate2 f c s
 | f == 1      = c : s
 | otherwise   = s ++ [c]

doQuery :: String -> String -> String
doQuery s q
 | length q == 1  = reverse s
 | otherwise      = operate2 (read f') c s
 where [_, f', c:_] = words q

main = do
    s <- getLine
    getLine
    qs <- lines <$> getContents
    let result = foldl doQuery s qs
    putStrLn result
