modified control trie to account for prefixes of all words in input