Create ternary tree