str=gets
n=gets.to_i
(0..n-1).each do |i|
  arr=gets.split
  s,e=arr[1].to_i, arr[2].to_i
  case arr[0]
  when "print" then
    puts str[s..e]
  when "reverse" then
    str[s..e]=str[s..e].reverse
  when "replace" then
    str[s..e]=arr[3]
  end
end