import           Control.Monad (replicateM)
import           Data.List     (foldl')

main :: IO ()
main = do
  s <- getLine
  q <- readLn
  qs <- replicateM q getQuery
  putStrLn $ solve s qs

data Query = Reverse | Cons Char | Snoc Char

getQuery :: IO Query
getQuery = do
  (t:xs) <- words <$> getLine
  return $ case t of
    "1" -> Reverse
    "2" -> let [f, c] = xs in case f of
      "1" -> Cons $ head c
      "2" -> Snoc $ head c

solve :: String -> [Query] -> String
solve s qs = toList $ foldl' g (fromList s) qs
  where g xs Reverse  = rev xs
        g xs (Cons c) = cons c xs
        g xs (Snoc c) = snoc xs c

data DoubleList a = DoubleList [a] [a]

fromList :: [a] -> DoubleList a
fromList xs = DoubleList xs []

toList :: DoubleList a -> [a]
toList (DoubleList xs ys)  = xs ++ reverse ys

rev :: DoubleList a -> DoubleList a
rev (DoubleList xs ys) = DoubleList ys xs

cons :: a -> DoubleList a -> DoubleList a
cons x (DoubleList xs ys) = DoubleList (x:xs) ys

snoc :: DoubleList a -> a -> DoubleList a
snoc (DoubleList xs ys) x = DoubleList xs (x:ys)
