6. Into each row of a $9 \times 9$ grid, Nigel writes the digits $1,2,3,4,5,6,7,8,9$ in order, starting at one of the digits and returning to 1 after 9 : for example, one row might contain $7,8,9,1,2,3,4,5,6$. The grid is gorgeous if each nine-digit number read along a row or column or along the diagonal from the top-left corner to the bottom-right corner or the diagonal from the bottom-left corner to the top-right corner is divisible by 9. How many of the $9^{9}$ possible grids are gorgeous?
SolUtion
Firstly, note that each row of the grid contains numbers $1-9$ in some order, so their sum is always $1+2+3+\ldots+9=45$, which is a multiple of 9 .
Then, notice that adding 9 to any cells in the grid does not change divisibility by 9 of any row, column, and diagonal sums. Hence, instead of writing rows as described in the question:
Nigel will start filling each row from the left with any number between 1 and 9 , and continue writing consecutive integers throughout the row. The example above will change to:
Consider a situation where Nigel completed the first eight rows of the grid in any of the $9^{8}$ possible ways (each way corresponds to choosing the values of $1 \leq a_{1}, a_{2}, \ldots, a_{8} \leq 9$ ):

Let $1 \leq a_{9} \leq 9$ be such a number that $a_{1}+a_{2}+\ldots+a_{8}+a_{9}$ is a multiple of 9 . There is exactly one value satisfying this condition, equal to $9-r$, where $r$ is the remainder when $a_{1}+a_{2}+\ldots+a_{8}$ is divided by 9 .
The only number Nigel can potentially use to start the ninth row is $a_{9}$, as any other number will make the sum of the first column not divisible by 9 . Note that the numbers in each column are larger by one than the corresponding numbers from the previous column. Hence, the column sums increase by 9 , going from left to right. This means that if the sum of the first column is divisible by 9 , so are the sums of all the other columns.
Consider now the sums on the two main diagonals:
- $a_{1}+\left(a_{2}+1\right)+\left(a_{3}+2\right)+\ldots+\left(a_{9}+8\right)=\left(a_{1}+a_{2}+\ldots+a_{9}\right)+(1+2+\ldots+7+8)=$ $\left(a_{1}+a_{2}+\ldots+a_{9}\right)+36$, which is a multiple of 9 .
- $\left(a_{1}+8\right)+\left(a_{2}+7\right)+\ldots+\left(a_{8}+1\right)+a_{9}=\left(a_{1}+a_{2}+\ldots+a_{9}\right)+(8+7+\ldots+2+1)=$ $\left(a_{1}+a_{2}+\ldots+a_{9}\right)+36$, which is a multiple of 9 .

This proves that for each of the $9^{8}$ choices of $\left(a_{1}, a_{2}, \ldots, a_{8}\right)$, there exists exactly one value of $a_{9}$ which completes a gorgeous grid. Hence, there are exactly $9^{8}$ possible gorgeous grids.