while line = gets
  n = gets.to_i
  n.times do
    c = gets.split
    x, y = c[1, 2].map(&:to_i)
    s = c[3]
    case c[0]
    when "replace"
      line[x..y] = s
      # pp "replace"
    when "reverse"
      line[x..y] = line[x..y].reverse
    when "print"
      puts line[x..y]
    end
  end
end
