Implement ternary search trie