an AC solution for word search.