Parent child list to ragged hierarchy

Hi, I am looking for a way to automatically create a ragged hierarchy for all possible combinations. The input is a simple file with only the parent - child combinations.

I've attached a screenshot of the parent child combination and how the ragged hierarchy should look like.


I think it is possible to do this when I combine the parent child list and ragged hierarchy list in one module and then create each level step by step, but I would like to avoid combining the 2 dimensions as the list will be extremely large!


Any ideas / suggestions?