Solve the reconstructing tenary tree from its preorder with an O(n^2) solution.