str = gets.chomp.split(//)
module Test
  def print(a, b)
    puts self[ran(a, b)].join
  end
  
  def reverse(a, b)
    self[ran(a, b)] = self[ran(a, b)].reverse
  end
  
  def replace(a, b, other)
    self[ran(a, b)] = other.to_s.split(//)
  end
  
  private
  def ran(a, b)
    return a.to_s.to_i..b.to_s.to_i
  end
end
str.extend(Test)
gets.to_i.times do
  str.send(*gets.chomp.split(" ").map(&:to_sym))
end