module Main where
--import Debug.Trace
import Data.List
import Data.Char
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

data Command = Replace Int Int String | Reverse Int Int | Print Int Int deriving (Show)

solve :: String -> [Command] -> [String]
solve _ [] = []
solve s (c:cs) =
    case c of
        Replace a b p -> solve (take a s ++ p ++ drop (b+1) s) cs
        Reverse a b   -> solve (take a s ++ reverse (target a b) ++ drop (b+1) s) cs
        Print   a b   -> target a b: solve s cs
    where target a b = take (b-a+1) (drop a s)

readLine:: IO [Int]
readLine = fmap (map read . words) getLine

readLines :: Int -> IO [Command]
readLines 0 = return []
readLines n = getLine >>=
    (\a -> fmap ((case words a of
        ["replace", a, b, p] -> Replace (read a) (read b) p
        ["reverse", a, b]    -> Reverse (read a) (read b)
        ["print", a, b]      -> Print   (read a) (read b)):) (readLines (pred n)))
            
main :: IO() 
main = do
    s <- getLine
    n <- readLn
    l <- readLines n
    mapM_ putStrLn (solve s l)

