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