str = gets.chomp
q = gets.to_i
q.times do
  data = []
  data = gets.chomp.split(" ")
  a = data[1].to_i
  b = data[2].to_i
  case data[0]
  when "print" then puts str[a..b]
  when "reverse" then str[a..b] = str[a..b].reverse
  when "replace" then str[a..b] = data[3]
  end
end