class StringDSL
  attr_reader :str
  def initialize(str)
    @str = str
  end

  def print(a, b)
    puts str[a, b+1]
  end

  def replace(a, b, p)
    str[a,b] = p
  end

  def reverse
    str[a,b] = str[a,b].reverse
  end
end

$stdin = DATA if $stdin.eof?

sd = StringDSL.new(gets.chomp)

gets

ARGF.each do |line|
  op, a, b, c = line.chomp.split
  a, b = [a, b].map(&:to_i)
  if c
    sd.instance_eval("#{op}(#{a},#{b},'#{c}')")
  else
    sd.instance_eval("#{op}(#{a},#{b})")
  end
end