MODE = "stdio"
require 'matrix'
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = 'xyz
  3
  print 0 2
  replace 0 2 abc
  print 0 2'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end
str=line[0]
n = line[1].to_i

(2..n+1).each do |m|
  c,a,b,p = line[m].split(" ")
  a = a.to_i
  b = b.to_i

  if c=="print"
    puts str[a..b]
  elsif c=="reverse"
    str[a..b] = str[a..b].reverse
  elsif c=="replace"
    str[a..b] = p
  end
end