3. In a $999 \times 999$ grid, some cells are white, and the others are red. Let $T$ be the number of cell groups $\left(C_{1}, C_{2}, C_{3}\right)$ such that $C_{1}$ and $C_{2}$ are in the same row, $C_{2}$ and $C_{3}$ are in the same column, and $C_{1}$ and $C_{3}$ are white, while $C_{2}$ is red. Find the maximum value of $T$.
3. First, prove: For an $n \times n$ grid, we have
$$
T \leqslant \frac{4 n^{4}}{27} \text {. }
$$

Let the $i$-th row have $a_{i}$ white cells, and the $j$-th column have $b_{j}$ white cells. Let $R$ be the set of red cells. For each red cell $(i, j)$, there are $a_{i} b_{j}$ valid quadruples $\left(C_{1}, C_{2}, C_{3}\right)$, where $C_{2}=(i, j)$. Therefore,
$$
T=\sum_{(i, j) \in R} a_{i} b_{j} \text {. }
$$

By the AM-GM inequality,
$$
\begin{array}{l}
T \leqslant \frac{1}{2} \sum_{(i, j) \in R}\left(a_{i}^{2}+b_{j}^{2}\right) \\
=\frac{1}{2} \sum_{i=1}^{n}\left(n-a_{i}\right) a_{i}^{2}+\frac{1}{2} \sum_{j=1}^{n}\left(n-b_{j}\right) b_{j}^{2},
\end{array}
$$

This is because the $i$-th row has $n-a_{i}$ red cells, and the $j$-th column has $n-b_{j}$ red cells.
For $0 \leqslant x \leqslant n$, by the AM-GM inequality,
$$
\begin{array}{l}
(n-x) x^{2}=\frac{1}{2}(2 n-2 x) x \cdot x \\
\leqslant \frac{1}{2}\left(\frac{2 n}{3}\right)^{3}=\frac{4 n^{3}}{27},
\end{array}
$$

with equality if and only if $x=\frac{2 n}{3}$.
Thus, $T \leqslant \frac{n}{2} \cdot \frac{4 n^{3}}{27}+\frac{n}{2} \cdot \frac{4 n^{3}}{27}=\frac{4 n^{4}}{27}$.
If $n=999$, then $x=\frac{2 n}{3}=666$.
For a coloring where each row and each column has 666 white cells, the equality in the inequality for $T$ holds.

The following example ensures that each row and each column has 666 white cells. If
$$
i-j \equiv 1,2, \cdots, 666(\bmod 999),
$$

then color the cell $(i, j)$ white, and color the other cells red. Thus, the maximum value of $T$ is
$$
\frac{4 \times 999^{4}}{27}=148 \times 999^{3} .
$$