Working with trees, to use family terminology is frequent. Thus, is said that a node is parent of another one, or child, or sibling, etcetera, with the equivalent meaning as the tree was genealogical.
Write a program that reads various general trees, and for each one prints all their relationships grandparent–grandchildren.
Input is a sequence of general trees of words, with the format of the exercise REREG. All the words of the same tree are different.
For each given tree, your program must print all the relationships grandparent–grandchildren in lexicogaphically order. Print a line in white after the output of each tree. Follow the format of the instance.
Input
12 L 3 K 2 J 0 I 1 H 1 G 0 F 0 E 4 D 0 C 0 B 0 A 0 3 Peter 2 John 0 Joseph 0 4 Peter 2 John 1 Joseph 0 Mary 0
Output
relationships grandparent-grandchildren: I G K H L A L B L C L D L I L J relationships grandparent-grandchildren: relationships grandparent-grandchildren: Peter Joseph