Solution to the wordchain problem.