I cannot decipher at all how the result maps to the original.

Your original shows 18 rows with a top-level of A. For those rows, your component goes from B-R. Then in the result version, in your second row, B is shown as a sub-number under A with a component of AB. Where does that result come from?

I just can't figure out how you took that original and ended up with that result. I suspect that if we can clarify the problem, the solution will be pretty easy.