import qualified Data.ByteString.Char8 as B
import qualified Data.Sequence as SQ

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

    let
        solve :: (SQ.Seq Char, SQ.Seq Char) -> Int -> Int -> IO (SQ.Seq Char, SQ.Seq Char, Int)
        solve (sqx,sqy) n cnt
            | n == 0 = return (sqx,sqy,cnt) 
            | otherwise = do
                xs <- words <$> getLine :: IO [String]
                case (length xs) of
                    1 -> do
                        solve (sqx,sqy) (n-1) (cnt+1)
                    _ -> do
                        let [_,f,[c]] = xs
                        case (f, even cnt) of
                            ("1", True) -> solve ((SQ.<|) c sqx, sqy) (n-1) cnt
                            ("1", False) -> solve (sqx, (SQ.|>) sqy c) (n-1) cnt
                            ("2", True) -> solve (sqx, (SQ.|>) sqy c) (n-1) cnt
                            ("2", False) -> solve ((SQ.<|) c sqx, sqy)  (n-1) cnt
        
        out :: SQ.Seq Char -> IO ()
        out sq =
            case SQ.viewl sq of
                c SQ.:< sq' -> do
                    putChar c
                    out sq'
                SQ.EmptyL -> return ()


    (sqx,sqy,cnt) <- solve (SQ.empty, SQ.empty) q 0

    if (even cnt)
        then do
            out sqx
            B.putStr s
            out sqy
            putStrLn ""
        else do
            out $ SQ.reverse sqy
            B.putStr $ B.reverse s
            out $ SQ.reverse sqx
            putStrLn ""