import Control.Monad

readQuery [_, f, c] = (read f, head c) :: (Int, Char)

convert :: Bool -> String -> (Int, Char) -> String
convert front s (f, c)
    | f == 1 && front = c : s
    | f == 2 && not front = c : s
    | otherwise = s ++ [c]

solve :: Bool -> String -> [[String]] -> String
solve front  s [] = if front then s else reverse s
solve front s (q:queries)
    | q == ["1"] = solve (not front) s queries
    | otherwise = solve front (convert front s (readQuery q)) queries

main :: IO ()
main = do
    s <- getLine
    q <- readLn
    queries <- map words <$> replicateM q getLine
    putStrLn $ solve True s queries