import Data.Char
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as MV
import Control.Monad
import Text.Printf
import Data.List

main1 = do
  -- w <- getLine
  -- t <- fmap (concat . map words . lines . map toLower) getContents
  let w = "computer"
      t = concat . map words . lines . map toLower $ "fdsalkfjo sda computer \nf lsdajf\n"
  putStrLn . show . length . filter (\n -> n == w) $ t

main2 = do
  dataSet <- fmap lines getContents
  let strings = map (\(s,hs) -> shuffleLoop hs (V.fromList s)) . disassembe $ dataSet
  mapM_ (putStrLn . V.toList) strings
  -- putStrLn ""

shuffleLoop [] vector = vector
shuffleLoop (h:hs) vector = shuffleLoop hs (shuffle h vector)

shuffle h vector = newVec
  where
    (fstVec,sndVec) = V.splitAt h vector
    newVec = sndVec V.++ fstVec

disassembe list = loop list []
  where
    loop ["-"] stack = stack
    loop (s:m:xs) stack = loop ys (stack ++ [(s,map read hs :: [Int])])
      where
        (hs,ys) = splitAt (read m :: Int) xs

main3 = do
  n <- readLn
  cards <- replicateM n $ fmap ((\(t:h:_) -> (t,h)) . words) getLine
  let (ts,hs) = solve3 cards
  printf "%d %d\n" ts hs

data ResultOneGame = TWin | HWin | Draw deriving Show

compereDict ([],[]) = Draw
compereDict ([],_) = HWin
compereDict (_,[]) = TWin
compereDict ((t:ts), (h:hs)) = case t `compare` h of
                                 GT -> TWin
                                 LT -> HWin
                                 EQ -> compereDict (ts, hs)

solve3 :: [(String,String)] -> (Int,Int)
solve3 list = foldl f (0,0) list
  where
    f :: (Int,Int) -> (String, String) -> (Int,Int)
    f (tScore, hScore) (tCard, hCard) = case compereDict (tCard, hCard) of
                                         TWin -> (tScore+3, hScore)
                                         HWin -> (tScore, hScore+3)
                                         Draw -> (tScore+1, hScore+1)

reverse4 (a:b:_) str = newVec
  where
    newVec = (V.take (read a) str) V.++  (V.reverse $ V.slice (read a) ((read b)-(read a)+1) str) V.++ (V.drop ((read b)+1) str)

replace4 (a:b:p:_) str = newVec
  where
    newVec = (V.take (read a) str) V.++  (V.fromList p) V.++ (V.drop ((read b)+1) str)

print4 (a:b:_) str = putStrLn . V.toList . V.slice (read a) ((read b)-(read a)+1) $ str

solve4 :: [[String]] -> V.Vector Char -> IO ()
solve4 ordersList str = loop ordersList str
  where
    loop [] _ = return ()
    loop ((order:ns):orders) s = do
      case order of
        "print" -> do
          print4 ns s
          solve4 orders s
        "reverse" -> do
          solve4 orders (reverse4 ns s)
        "replace" -> do
          solve4 orders (replace4 ns s)

main = do
  str <- fmap V.fromList getLine
  _ <- getLine
  orderList <- fmap (map words . lines) getContents
  solve4 orderList str

