str = gets.chomp
q = gets.chomp.to_i
q.times do
  statement, a, b, p = gets.chomp.split(/\s/)
  a = a.to_i
  b = b.to_i
  case statement
  when "print" then
    puts str.slice(a, b)
  when "reverse" then
    str[a..b] = str[a..b].reverse
    puts str
  when "replace" then
    str[a..b] = p
    puts str
  end
end