import Control.Monad
import Control.Applicative

slice a b s = drop a $ take (b+1) s

print' a b s = putStrLn $ slice a b s
reverse' a b s = take a s ++ reverse (slice a b s) ++ drop (b+1) s
replace' a b p s = take a s ++ p ++ drop (b+1) s

exec [] _ = return ()
exec (all@(op:args):xs) s
	| op == "print"   = do 
						print' a b s
						exec xs s
	| op == "reverse" = exec xs (reverse' a b s)
	| op == "replace" = exec xs (replace' a b (last args) s)
		where [a,b] = map read $ take 2 args

main = do
	s <- getLine
	n <- readLn
	op <- replicateM n $ words <$> getLine
	exec op s