str = STDIN.gets.chomp()
order_num = STDIN.gets.chomp().to_i

for i in 0..order_num - 1 do
    line = STDIN.gets.chomp()
    order = line.split(" ")
    case order[0]
    when "print"
        puts str[order[1].to_i..order[2].to_i]
    when "reverse"
        str[order[1].to_i..order[2].to_i] = str[order[1].to_i..order[2].to_i].reverse
    when "replace"
        str[order[1].to_i..order[2].to_i] = order[3]
    end
end