str = gets.chomp
gets.to_i.times do
  command, a, b, p = gets.split
  a = a.to_i
  b = b.to_i
  case command
  when "replace"
    str[a..b] = p
  when "reverse"
    str[a..b] = str[a..b].reverse
  when "print"
    puts str[a..b]
  end
end