str = gets.chomp
gets.to_i.times do
  line = gets.chomp.split
  cm = line[0]
  s = line[1].to_i
  e = line[2].to_i
  if cm == "print"
    puts str[s..e]
  elsif cm == "reverse"
    if s == 0
      str = str[s..e].reverse + str[(e+1)..-1]
    else
      str = str[0..(s-1)] + str[s..e].reverse + str[(e+1)..-1]
    end
  else
    p = line[3]
    str[s..e] = p
  end
end

