str = gets.chomp
gets

ARGF.each do |line|
  command, a, b, c = line.chomp.split
  a = a.to_i
  b = b.to_i

  case command
  when "print"
    puts str[(a..b)]
  when "replace"
    str.gsub!(str[a..b], c)
  when "reverse"
    aa = str.slice(0...a)
    bb = str.slice(a..b)
    bb.reverse!
    cc = str.slice((b+1)..str.length)
    str = aa + bb + cc
  end
end