An N×M grid holds one uppercase letter in each cell. Given a word S, write a program that decides whether the word S is in the grid.
The word S is in the grid when you can start at one cell and read the letters of S in order through neighboring cells. The direction can be up, down, left, right, or one of the four diagonals: upper left, upper right, lower left, lower right. The direction must not change partway.