The hard part in what you're talking about is determining an appropriate display order. Your example illustrates that the non-trivial case can occur. Therefore, you probably want a topological sort (e.g. by Sort::Topological or the topological_sort method of Graph) to generate an optimal order. Once you've done that, the rest is a cinch.
But just having topological sort doesn't solve all the problems. You first need to generate an appropriate DAG based on the input lists. You could build a graph, adding each input list, such that each edge in the input list increments the corresponding edge in the graph. When that's done, invert the weight (count) of each edge, and extract a minimum spanning tree (also provided by Graph) from the graph. Use that as the input to the topological sort.
A word spoken in Mind will reach its own level, in the objective world, by its own weight