I have a list of Skus and substitute products. The amount of times a sku is listed in the left column is based on how many substitutes exist.

If a sku is listed as a substitute product on the right, the product on the left and all other substitutes on the right are substitutes on it. Im trying to get all possible combinations. Here is an example of what i want the end product to be.

The example is 5 subs but it could be any number depending on sku. Also the order I have those subs in is random (sub 2, sub 3, etc..), no specific order needed.