'creating a family tree from unordered input

I need to create a family tree by given input list where generations are not in the order. For example, given list is ['CHILDREN father_name,mother_name,children_name']

['CHILDREN Max,Anna,Stefanny, Joe', 'CHILDREN Anton,Vika,Max','Children Joe,Karla,Sasha']

Tree should be

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source