This is similar to Case Play 10.3.1 A.
In 1, the foul occurs during a loose ball play, therefore the enforcement spot is the previous spot.
In 2, the foul occurs during a running play, therefore the enforcement spot is the end of the run.
The location of B's foul is never a factor, just the timing during the play.