w = gets.chomp.split("")
gets
while cmd = gets do
  cmd, op1, op2, op3 = cmd.split
  op1 = op1.to_i
  op2 = op2.to_i
  case cmd
  when "print"
    puts w[op1..op2].join
  when "reverse"
    w[op1..op2] = w[op1..op2].reverse
  when "replace"
    w[op1..op2] = op3.split("")
  end
end