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

main :: IO ()
main = do
    s <- getLine :: IO String
    q <- readLn :: IO Int
    res <- newIORef 0

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

    (bsx,bsy) <- solve (B.empty, B.empty) q
    res' <- readIORef res

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