7. (Problem from the 54th Belarusian Mathematical Olympiad) In an $n \times n (n \geqslant 3)$ grid, each cell is filled with a certain integer. It is known that the sum of all numbers in any $3 \times 3$ subgrid is even, and the sum of all numbers in any $5 \times 5$ subgrid is also even. Find all $n$ such that the sum of all numbers in the grid is even.
7. $n=3 k, n=5 k, k \in \mathbf{N}_{+}$.

Obviously, when $n=3 k(5 k)$, the $n \times n$ grid can be divided into $k^{2}$ $3 \times 3(5 \times 5)$ units. Since the sum of all integers in any unit is even, the sum of all integers in the $n \times n$ grid is also even.
Below is an example to prove that if $n$ is neither a multiple of 3 nor a multiple of 5, then the sum of all integers in the grid can be odd.
Consider the sequences:
$1011011011 \cdots$
and $1000110001100011000110001 \cdots$.
These two sequences have periods of three and five, respectively. Let $A_{k}$ and $B_{k}$ be the sums of the first $k$ terms of sequences (1) and (2), respectively. It is clear that for any $k, m \in \mathbf{N}_{+}$, we have
$A_{k+15 m} \equiv A_{k}(\bmod 2), B_{k+15 m} \equiv B_{k}(\bmod 2)$.
Fill the $n \times n$ grid with 0s and 1s according to the following rules:
If the $k$-th term of (1) is 1, fill the $k$-th column of the grid with the first $n$ terms of (2);
If the $k$-th term of (1) is 0, fill the $k$-th column of the grid entirely with 0s. It is easy to prove that the total sum of numbers in the grid is equal to $A_{n} B_{n}$. Note that
$$
\begin{array}{l}
A_{1}=1, A_{2}=1, A_{4}=3, A_{7}=5, A_{8}=5, A_{11}=7, A_{13}=9, \\
A_{14}=9, \\
B_{1}=1, B_{2}=1, B_{4}=1, B_{7}=3, B_{8}=3, B_{11}=5, B_{13}=5, \\
B_{14}=5. \\
\end{array}
$$

Therefore, if $n \neq 3 k$ and $n \neq 5 k\left(k \in \mathbf{N}_{+}\right)$, then the sum of all numbers in the $n \times n$ grid is odd.
Verification shows that the sum of all numbers in any $3 \times 3$ and $5 \times 5$ grid is even. The table shown below is an example of a $7 \times 7$ grid.