str = gets.to_s
q = gets.to_i
w = []

q.times do
    x, a, b, q = gets.split.map(&:to_s)
    a = a.to_i
    b = b.to_i

    case x
    when "reverse" then
        str[a..b] = str[a..b].reverse
    
    when "replace"
        str[a..b] = str[a..b].replace(q)
    
    when "print" then
        print str[a..b]
    
    end
end