12. Let $X=\{1,2, \cdots, 10\}, f: X \rightarrow X$ be a mapping satisfying
(1) $f \circ f=I_{X}$, where $f \circ f$ is the composite mapping, and $I_{X}$ is the identity mapping on $X$;
(2) $|f(i)-i| \leqslant 2$, for any $i \in X$.
Find the number of mappings $f$.
Consider the number of mappings $a_{n}$ that satisfy the conditions for $X=\{1,2, \cdots, n\}$. Clearly, for any $x \in X$, either $f(x)=x$, or $f(x)=y(x \neq y)$, and $f(y)=x$.

From condition (2), if $f(1)=1$, removing element 1, the corresponding number of mappings is $a_{n-1}$;
if $f(1)=2$, there must be $f(2)=1$, removing elements 1,2, the corresponding number of mappings is $a_{n-2}$;
if $f(1)=3$, there must be $f(3)=1$, at this point $f(2)$ has two cases:
(1) if $f(2)=2$, removing elements $1,2,3$, the corresponding number of mappings is $a_{n-3}$;
(2) if $f(2)=4$, there must be $f(4)=2$, removing elements $1,2,3,4$, the corresponding number of mappings is $a_{n-4}$.

Since there are no other possible values for $f(1)$, we have $a_{n}=a_{n-1}+a_{n-2}+a_{n-3}+a_{n-4}$.
Calculating, we get $a_{1}=1, a_{2}=2, a_{3}=4, a_{4}=8$, so $a_{5}=15, a_{6}=29, a_{7}=56, a_{8}=108, a_{9}=208, a_{10}=$ 401.