How many square matrices are there with given columns, rows and diagonals Suppose we have $n\times n$ matrix that contains numbers from $1$ to $n^2$.
How many matrices are there that their $n$ columns, $n$ rows and $2n$ diagonals contain given numbers?
For example $3\times 3$ matrix:
\begin{pmatrix} 
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{pmatrix}
Its rows are $(1,2,3),(4,5,6),(7,8,9)$.
Its columns are $(1,4,7),(2,5,8),(3,6,9)$.
Its diagonals are $(1,5,9),(2,6,7),(3,4,8),(1,6,8),(2,4,9),(3,5,7)$.
If we join them all together sorted inside and sorted overall we get:
$$\big((1,2,3),(1,4,7),(1,5,9),(1,6,8),(2,4,9),(2,5,8),(2,6,7),$$$$(3,4,8),(3,5,7),(3,6,9),(4,5,6),(7,8,9)\big)$$
Question is how many $3\times 3$ matrices there are with the same sorted set?
I brute-forced it for $n=3$. And the number is $432$. But I am not able to figure out a formula for it. The number $432$ is divisible by $9$ which is of course because the original matrix can be shifted to $3\cdot 3=9$ different positions preserving the ordered set. And also by $16$ as we can rotate whole matrix $4$ times by $90$ degrees and there are $4$ mirror images for each one. $432/9/16=3$ so there must be $3$ fundamental matrices from which we can generate all $432$ by shifting, rotating and mirroring. (If I am not mistaken.)
Just one example out of $432$ that has the same sorted set as original matrix:
\begin{pmatrix}
 4 & 2 & 9 \\
 1 & 8 & 6 \\
 7 & 5 & 3 \\
\end{pmatrix}
...and perhaps additional question: How to produce all the required matrices algorithmically one by one?

I believe the previous answers have sufficiently addressed the $3\times3$ matrix. In this post I will consider the $4\times4$ matrix below.
\begin{pmatrix}
0&1&2&3\\
4&5&6&7\\
8&9&A&B\\
C&D&E&F
\end{pmatrix}
Consider first the groups containing $0$:
$$(0,1,2,3),(0,4,8,C),(0,5,A,F),(0,7,A,D)$$
We see that $A$ appears in two of these groups. As such, there is only one position (relative to the position of $0$) in which $A$ can be placed, as shown here with $0$ in the upper left corner, where it will be fixed for the purpose of counting:
\begin{pmatrix}
0&?&?&?\\
?&?&?&?\\
?&?&A&?\\
?&?&?&?
\end{pmatrix}
Now there are $8$ ways to complete the two diagonals containing both $0$ and $A$:
\begin{matrix}
\begin{pmatrix}
0&?&?&?\\
?&5&?&7\\
?&?&A&?\\
?&D&?&F
\end{pmatrix}
&
\begin{pmatrix}
0&?&?&?\\
?&5&?&D\\
?&?&A&?\\
?&7&?&F
\end{pmatrix}
&
\begin{pmatrix}
0&?&?&?\\
?&7&?&5\\
?&?&A&?\\
?&F&?&D
\end{pmatrix}
&
\begin{pmatrix}
0&?&?&?\\
?&7&?&F\\
?&?&A&?\\
?&5&?&D
\end{pmatrix}
\\[2ex]
\begin{pmatrix}
0&?&?&?\\
?&D&?&5\\
?&?&A&?\\
?&F&?&7
\end{pmatrix}
&
\begin{pmatrix}
0&?&?&?\\
?&D&?&F\\
?&?&A&?\\
?&5&?&7
\end{pmatrix}
&
\begin{pmatrix}
0&?&?&?\\
?&F&?&7\\
?&?&A&?\\
?&D&?&5
\end{pmatrix}
&
\begin{pmatrix}
0&?&?&?\\
?&F&?&D\\
?&?&A&?\\
?&7&?&5
\end{pmatrix}
\end{matrix}
Next we will take one of these and fill in the remaining elements, first noting that the column containing both $D$ and $5$ must also contain both $1$ and $9$, and that $9$ does not appear in any group with $0$, so this column must be $(1,D,9,5)$. Likewise, the column $(?,F,?,7)$ must be $(3,F,B,7)$. The second and fourth rows can also be completed in this manner, and this leads to exactly one solution for each of the eight partial solutions:
\begin{matrix}
\begin{pmatrix}
0&?&?&?\\
?&D&?&F\\
?&?&A&?\\
?&5&?&7
\end{pmatrix}
&\implies&
\begin{pmatrix}
0&1&2&3\\
C&D&E&F\\
8&9&A&B\\
4&5&6&7
\end{pmatrix}
\end{matrix}
With $8$ solutions for each of the $4^2$ possible positions for the $0$, there are a total of $8\cdot4^2=128$ qualifying matrices.
