def print(a, b, str)
  puts str.slice(a..b)
end

def reverse(a, b, str)
  str[a..b] = str.slice(a..b).reverse
end

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

commands = ['print', 'reverse', 'replace']

str = gets.chomp
n = gets.chomp.to_i

n.times do
  command, *args = gets.chomp.split("\s")
  args[0], args[1] = args[0].to_i, args[1].to_i
  __send__(command, *(args+[str])) if commands.include?(command)
end