I believe that team B has two options:
1. Accept the penalty and enforce from team A's endzone, thus resulting in a safety - 2 points for team B, team A free kicks from the A-20. 9-4-1-c, 10-2-2-d-4-a, 10-2-2-c-1
2. Accept the penalty as a tack-on to the spot where team B would next put the ball in play, the A-8 - Team B's ball 1st and Goal from the A-4. Note: when a scrimmage kick goes out of bounds, it belongs to the receiving team at the out of bounds spot. 9-4-1-c, 10-2-4, 6-3-13
I'm not in love with the phrasing in 6-3-13 "may be enforced at the previous spot with the down repeated or at the spot where the subsequent dead ball belongs to Team B". I would prefer it said "may be enforced by rule at the previous spot or at the spot where the subsequent dead ball belongs to Team B". But I think the intent of the rule is to allow this to be a tack-on.