s = gets.chomp
gets.to_i.times{
    x = gets.split
    a = x[1].to_i
    b = x[2].to_i
    case x[0]
    when "print" then
        puts s[a, b - a + 1]
    when "reverse" then
        s[a, b - a + 1] = s[a, b - a + 1].reverse
    when "replace" then
        s[a, b - a + 1] = x[3]
    end
}
