str = gets.chomp
gets.to_i.times do
  command = gets.split
  a = command[1].to_i
  b = command[2].to_i
  case command[0]
  when "print"
    puts str[a..b]
  when "reverse"
    str = str[0, a] + str[a..b].reverse + str[b + 1..-1]
  when "replace"
    str = str[0, a] + command[3] + str[b + 1..-1]
  end
end
