#!/usr/bin/env ruby

word = gets.chomp
loop_number = gets.to_i
loop_number.times  do 
    line = gets.split
    case line[0]
    when "replace" then
        word[line[1].to_i..line[2].to_i] = line[3]
    when "reverse" then
        word[line[1].to_i..line[2].to_i] = word[line[1].to_i..line[2].to_i].reverse
    when "print"
        puts word[line[1].to_i..line[2].to_i]
    end
end
