org=gets.chomp
t=gets.to_i
t.times do
  com=gets.split(' ')
  s=com[1].to_i
  e=com[2].to_i
  case com[0]
  when "replace" then
       str=com[3]
       org[s..e]=str
  when "reverse" then
       tmp=org[s..e].reverse
       if s-1 > 0 then org=org[0..s-1]+tmp end
       if e+1 < org.length then org=tmp+org[e+1,org.length]  end
  when "print" then
       printf("%s\n", org[s..e])
  end
end