s = gets.chomp.split("")
q = gets.to_i
q.times do
  order = gets.chomp.split(" ")
  if order[0] == "print"
    for i in order[1].to_i..order[2].to_i do
      print s[i]
    end
    puts
  elsif order[0] == "reverse"
    s[order[1].to_i..order[2].to_i] = s[order[1].to_i..order[2].to_i].reverse
  elsif order[0] == "replace"
    s[order[1].to_i..order[2].to_i] = order[3].split("")
  end
end