import           Control.Applicative
import           Control.Monad
import           Data.List

main :: IO ()
main = do
  text <- getLine
  num <- getLine
  cmds <- replicateM (read num) (words <$> getLine)
  putStr $ unlines $ snd $ foldl exec (text,[]) cmds
  where
    exec::(String, [String])->[String]->(String, [String])
    exec(cur, out) (cmd:a:b:s1)
      | cmd=="reverse" = (left ++ reverse mid  ++ right, out)
      | cmd=="replace" = (left ++ head s1 ++ right, out)
      | cmd=="print" = (cur, out ++ [mid])
      where
        start = read a
        end = read b
        left = take start cur
        mid = take (end - start + 1) (drop start cur)
        right = drop (end + 1) cur

