12. Let $n$ be a given positive integer, consider the set of points in the Cartesian coordinate system $x O y$
$$
T=\{(x, y)|| x|=| y \mid \leq n, x, y \in \mathbf{Z}\}
$$

For two points $P, Q$ in $T$, $P, Q$ are called "adjacent" if and only if $|P Q|=\sqrt{2}$ or $P Q$ is parallel to one of the coordinate axes. Each point in $T$ is colored with one of three colors: red, blue, or green, such that any two adjacent points are colored differently. Find the number of coloring ways.
Unfold from the point $(0,0)$, there are a total of $n$ layers of squares, with coloring requirements: adjacent vertices of the square must have different colors, and points adjacent to the upper layer must also be different. The point $(0,0)$ is colored with color 3, and the four vertices of the first square are colored with 12:
$A$ class: $\begin{array}{ll}12 \\ 2 & 1\end{array}$ (a total of 2 colors used) If the upper layer is $A$ class, the coloring situation of the next layer is:
$B$ class: $\begin{array}{ll}12 \\ 3 & 1\end{array}$ (a total of 3 colors used) If the upper layer is $B$ class, the coloring situation of the next layer is:
$$
\left\{\begin{array}{llllllllll}
A \text { two types } & 2 & 1 & 3 & 1 & & & & & \\
& 1 & 2 & 1 & 3 & & & & & \\
& 2 & 3 & 2 & 1 & 3 & 1 & 3 & 1 \\
B \text { four types } & 1 & 2 & 1 & 3 & 1 & 2 & 2 & 3
\end{array} .\right.
$$

Construct the sequence, $O_{n}$ represents the number of $A$ class coloring methods for the $n$-th layer, $b_{n}$ represents the number of $B$ class coloring methods for the $n$-th layer
$$
\left\{\begin{array}{l}
a_{n+1}=3 a_{n}+2 b_{n} \\
b_{n+1}=4 a_{n}+4 b_{n}
\end{array} \quad a_{1}=1, b_{1}=0\right.
$$

Therefore,
Construct $\lambda: a_{n+1}+J \cdot b_{n+1}=(3+4 \lambda) a_{n}+(2+4 d) b_{n}$, satisfying $\lambda=\frac{2+4 d}{3+4 d} \Rightarrow 4 \lambda^{2}-\lambda-2=0, \lambda=\frac{1 \pm \sqrt{33}}{8}$.
Also, $a_{1}=1, b_{1}=0$, so
$$
\left\{\begin{array}{l}
a_{n}+\frac{1+\sqrt{33}}{8} b_{n}=\left(\frac{7+\sqrt{33}}{2}\right)^{n-1} \\
a_{n}+\frac{1-\sqrt{33}}{8} b_{n}=\left(\frac{7-\sqrt{33}}{2}\right)^{n-1}
\end{array}\right.
$$

Solving, we get
$$
\left\{\begin{array}{l}
a_{n}=\frac{\sqrt{33}-1}{2 \sqrt{33}} \cdot\left(\frac{7+\sqrt{33}}{2}\right)^{n-1}+\frac{\sqrt{33}+1}{2 \sqrt{33}} \cdot\left(\frac{7-\sqrt{33}}{2}\right)^{n-1} \\
b_{n}=\frac{4}{\sqrt{33}} \cdot\left(\frac{7+\sqrt{33}}{2}\right)^{n-1}-\frac{4}{\sqrt{33}} \cdot\left(\frac{7-\sqrt{33}}{2}\right)^{n-1}
\end{array}\right.
$$

Therefore,
$$
a_{n}+b_{n}=\frac{\sqrt{33}+7}{2 \sqrt{33}} \cdot\left(\frac{7+\sqrt{33}}{2}\right)^{n-1}+\frac{\sqrt{33}-7}{2 \sqrt{33}} \cdot\left(\frac{7-\sqrt{33}}{2}\right)^{n-1}
$$

Finally, there are $P_{3}^{3}=6$ ways to arrange the color numbers 1, 2, 3 with red, green, and blue, so the number of coloring methods is
$$
6\left(a_{n}+b_{n}\right)=\frac{6}{\sqrt{33}}\left[\left(\frac{7+\sqrt{33}}{2}\right)^{n}-\left(\frac{7-\sqrt{33}}{2}\right)^{n}\right] \text { ways }
$$