In your first scenario, fouls don’t offset violations, the violation is canceled when a live ball foul is accepted. So if Team A (not K) accepts the holding foul, the illegal touching goes away and you would entice the holding from the previous spot because it is a foul by the team not in possession and the basic spot on a free kick play is the previous spot. Otherwise, if they decline the holding, Team B (not R) will take the illegal touching and get the ball.
As to mechanics, think about why we use bean bags. We use them to Mark spots we may need. So we always bean bat illegal touching, but we never need to bean bag touches by Team B because that spot doesn’t matter. We need to know if they touched the ball, but where that touch occurred is irrelevant.
In your second scenario, Team B is always eligible to block on a free kick. So all you have is illegal touching and it will be Team B’s ball.