str = $stdin.gets(chomp:true)
odr_q = $stdin.gets(chomp:true).to_i
order = []

odr_q.times do
  order << $stdin.gets.split
end

order.each do | cmd |
  cmd[1] = cmd[1].to_i
  cmd[2] = cmd[2].to_i
  case cmd[0]
  when  "print"
    puts str[cmd[1]..cmd[2]]
  when  "reverse"
    str[cmd[1]..cmd[2]] = str[cmd[1]..cmd[2]].reverse
  when  "replace"
    str[cmd[1]..cmd[2]] = cmd[3]
  end
end

