2. Given a prime number $p$. Let $A=\left(a_{i j}\right)$ be a $p \times p$ matrix, satisfying
$$
\left\{a_{i j} \mid 1 \leqslant i, j \leqslant p\right\}=\left\{1,2, \cdots, p^{2}\right\} .
$$

We are allowed to perform the following operation on a matrix: select a row or a column, and simultaneously add 1 or subtract 1 from each number in that row or column. If it is possible to transform all elements of $A$ to 0 through a finite number of such operations, then $A$ is called a "good matrix". Find the number of good matrices $A$. (Provided by Zhenhua Fu)
2. By the commutative and associative laws of addition and subtraction, operations on the same row or column can be combined and performed without considering the order of the operations.

Assume that the final result of all operations is to subtract $x_{i}$ from each number in the $i$-th row and to subtract $y_{j}$ from each number in the $j$-th column, where $x_{i}, y_{i} (1 \leqslant i, j \leqslant p)$ can be any integers.

From the problem, we know that $a_{ij} = x_{i} + y_{j}$ holds for all $i, j (1 \leqslant i, j \leqslant p)$.

Since all numbers in the table are distinct, $x_{1}, x_{2}, \cdots, x_{p}$ are distinct, and $y_{1}, y_{2}, \cdots, y_{p}$ are also distinct. Without loss of generality, assume $x_{1} < x_{2} < \cdots < x_{p}$, because swapping the values of $x_{i}$ and $x_{j}$ is equivalent to swapping the $i$-th row and the $j$-th row, which does not change the problem or the conclusion. Similarly, assume $y_{1} < y_{2} < \cdots < y_{p}$. Thus, assume that each row from left to right is increasing, and each column from top to bottom is also increasing.

From the above discussion, we have $a_{11} = 1, a_{12} = 2$ or $a_{21} = 2$. Without loss of generality, assume $a_{12} = 2$. Otherwise, reflect the entire table about the main diagonal, which does not change the problem or the conclusion.

We will prove by contradiction that $1, 2, \cdots, p$ are all in the first row.

Assume that $1, 2, \cdots, k (2 \leqslant k < p)$ are in the first row, and $k+1$ is not in the first row. Thus, $a_{21} = k+1$. We need to prove that the first row consists of several "blocks" of $k$ consecutive integers, i.e., the first $k$ numbers form a block, the next $k$ numbers form another block, and so on.

If not, suppose the first $n$ groups of $k$ numbers are blocks, but the next $k$ numbers do not form a block (or there are fewer than $k$ numbers left). This implies that for $j = 1, 2, \cdots, n$, $y_{(j-1)k+1}, y_{(j-1)k+2}, \cdots, y_{jk}$ form a block. Therefore, the first $nk$ columns can be divided into $pn$ sub-tables of size $1 \times k$: $a_{i, (j-1)k+1}, a_{i, (j-1)k+2}, \cdots, a_{i, jk} (i = 1, 2, \cdots, p; j = 1, 2, \cdots, n)$, and each sub-table contains $k$ numbers that form a block.

Now assume $a_{1, nk+1} = a$, and let $b$ be the smallest positive integer such that $a + b$ is not in the first row. Then $b \leqslant k-1$.
Since $a_{2, nk+1} - a_{1, nk+1} = x_{2} - x_{1} = a_{21} - a_{11} = k$,
we have $a_{2, nk+1} = a + k$.
Thus, $a + b$ must be in the first $nk$ columns. This means $a + b$ is contained in one of the previously mentioned $1 \times k$ blocks, but $a$ and $a + k$ are not in that block, leading to a contradiction.
Therefore, the first row consists of several blocks.
In particular, $k \mid p$. However, $1 < k < p$, and $p$ is a prime number, which leads to a contradiction.

Thus, the first row of the table is exactly $1, 2, \cdots, p$, and the $k$-th row must be $(k-1)p + 1, (k-1)p + 2, \cdots, kp$.

Therefore, a good matrix $A$ can always be transformed into a unique form by swapping rows, swapping columns, and reflecting about the main diagonal.
Hence, the number of good matrices is $2(p!)^2$.