str = gets.chomp
q_size = gets.to_i
q_size.times do
  q = gets.chomp.split
  q[1] = q[1].to_i
  q[2] = q[2].to_i
  case q[0]
  when "print"
    puts str[q[1]..q[2]]
  when "replace"
    str[q[1]..q[2]] = q[3]
  when "reverse"
    str[q[1]..q[2]] = str[q[1]..q[2]].reverse
  end
end