Find the number of ways of arranging the numbers 1, 2, 3, ..., 9 in a 3 by 3 grid, so that consecutive numbers are in squares that have a side in common. For example:
3 4 5
2 1 6
9 8 7