text = gets.chomp
q = gets.to_i
q.times do
  commands = gets.split(" ")
  a = commands[1].to_i
  b = commands[2].to_i
  if(commands[0] == "print") then
    printf "%s\n", text[a..b]
  elsif(commands[0] == "reverse") then
    word = text.slice(a..b)
    text[a..b] = word.reverse
  else
    text[a..b] = commands[3]
  end
end