import qualified Data.ByteString.Char8 as B
import Data.IORef

main :: IO ()
main = do
    s <- B.getLine :: IO B.ByteString
    q <- readLn :: IO Int

    let
        solve :: (B.ByteString, B.ByteString) -> Int -> Int -> IO (B.ByteString, B.ByteString, Int)
        solve (bsx,bsy) n cnt
            | n == 0 = return (bsx,bsy, cnt) 
            | otherwise = do
                xs <- words <$> getLine :: IO [String]
                case (length xs) of
                    1 -> do
                        solve (bsx,bsy) (n-1) (cnt+1)
                    _ -> do
                        let [_,f,[c]] = xs
                        case (f, even cnt) of
                            ("1", True) -> solve (B.cons c bsx, bsy) (n-1) cnt
                            ("1", False) -> solve (bsx, B.snoc bsy c) (n-1) cnt
                            ("2", True) -> solve (bsx, B.snoc bsy c) (n-1) cnt
                            ("2", False) -> solve (B.cons c bsx, bsy) (n-1) cnt

    (bsx,bsy,cnt) <- solve (B.empty, B.empty) q 0

    if (even cnt)
        then do
            B.putStr bsx
            B.putStr s
            B.putStrLn bsy
        else do
            B.putStr $ B.reverse bsy
            B.putStr $ B.reverse s
            B.putStrLn $ B.reverse bsx