str = gets
gets.to_i.times do
    q, a, b, c = gets.split
    a = a.to_i
    b = b.to_i
    case q
    when "print"
        puts str[a..b]
    when "reverse"
        str[a..b] = str[a..b].reverse
    when "replace"
        str[a..b] = c
    end
end