Ternary Huffman Coding

I understand and I am perfectly capable of applying the binary Huffman coding, however, I keep getting stuck on ternary. I know that instead of two lowest probability characters I need to join three etc. But when working out the codewords, some of them do not match, which is probably the way I keep drawing the trees. For example, my coding for x4 is 21 and x5 = 210, however they are wrong. How do you actually draw the trees?
The following link contains the correct solutions but does not say how to work it out. It's question 5.4c
[HTML]http://www.ifp.illinois.edu/~srikant/ECE563/hw3_sol.pdf[/HTML]