import Control.Applicative
import Control.Monad

main :: IO ()
main = do
  str <- getLine
  q <- readLn
  cmds <- map words <$> replicateM q getLine
  cmdLoop str cmds

cmdLoop :: String -> [[String]] -> IO ()
cmdLoop _ [] = return ()
cmdLoop str ((c : a : b : s) : cmds)
  | c == "replace" = cmdLoop (s1 ++ head s ++ s4) cmds
  | c == "reverse" = cmdLoop (s1 ++ reverse s3 ++ s4) cmds
  | c == "print"   = do
      putStrLn s3
      cmdLoop str cmds
      where
        [a', b'] = map read [a, b]
        (s1, s2) = splitAt a' str
        (s3, s4) = splitAt (b' - a' + 1) s2

