str = gets.chomp
q = gets.to_i

ARGF.each_line do |line|
  op, a, b, p = line.chomp.split
  a = a.to_i
  b = b.to_i
  str_length = str.length
  
  case op
  when "print"
    puts str.slice(a..b)
  when "reverse"
    str = str.slice(0...a) + str.slice(a..b).reverse + str.slice((b+1)..str_length)
  when "replace"
    str = str.slice(0...a) + p + str.slice(b+1..str_length)
  end
end