import Control.Applicative
import Control.Monad
import Data.Array
import Data.Array.ST
import Data.Char
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

doOp :: Array Int Char -> IO (Array Int Char)
doOp ary = do
  (op:a0:b0:rs) <- words <$> getLine
  let a = read a0 :: Int
  let b = read b0 :: Int
  case op of
    "print"   -> do
      forM_ [a..b] $ \i -> do
        putChar $ ary ! i
      putChar '\n'
      return ary
    "reverse" -> do
      return $ ixmap (bounds ary) f ary
       where
        f i
          | i < a     = i
          | i > b     = i
          | otherwise = a + b - i
    "replace" -> return $ runSTArray $ do
      let p = listArray (a,b) (head rs) :: Array Int Char
      mary <- thaw ary
      forM_ [a..b] $ \i -> do
        writeArray mary i (p!i)
      return mary

main :: IO ()
main = do
  str <- getLine
  let ary = listArray (0, length str - 1) str
  n <- readLn
  void $ foldM (\acc _ -> doOp acc) ary [1..n]

