lines = STDIN.read.split("\n")
word = lines.shift
n = lines.shift.to_i
lines.each do |line|
  op, *args = line.split(" ")
  case op
  when "print" then
    a, b = args.map(&:to_i)
    puts word[a..b]
  when "reverse" then
    a, b = args.map(&:to_i)
    word[a..b] = word[a..b].reverse
  when "replace" then
    a, b, p = args[0].to_i, args[1].to_i, args[2]
    word[a..b] = p
  end
end