21.2.7 Let $n$ and $m$ be positive integers, $A=\{1,2, \cdots, n\}, B_{n}^{m}-\left\{\left(a_{1}, a_{2}, \cdots, a_{m}\right) \mid a_{i}\right.$ $\in A, i=1,2, \cdots, m\}$ satisfy:
(1) $\left|a_{i}-a_{i+1}\right| \neq n-1, i=1,2, \cdots, m-1$;
(2) $a_{1}, a_{2}, \cdots, a_{m}(m \geqslant 3)$ contain at least three different elements.
Find the number of elements in $B_{n}^{m}$ and $B_{6}^{3}$.
Given the problem, if $B_{n}^{m}$ is non-empty, then $n, m \geqslant 3$.
First, we calculate the number of $\left(a_{1}, a_{2}, \cdots, a_{m}\right)$ that only satisfy condition (1), i.e., temporarily ignoring condition (2).
Condition (1) states: In $\left(a_{1}, a_{2}, \cdots, a_{m}\right)$, 1 and $n$ are not adjacent.
Let the number of such $\left(a_{1}, a_{2}, \cdots, a_{m}\right)$ be $S_{m}$, where $x_{m}$ start with 1, $y_{m}$ start with $2, \cdots, n-1$, and $z_{m}$ start with $n$, then $S_{m}=x_{m}+y_{m}+z_{m}$. Therefore, we have the recurrence relations:
$$
\left\{\begin{array}{l}
x_{m+1}=x_{m}+y_{m}, \\
y_{m+1}=(n-2)\left(x_{m}+y_{m}+z_{m}\right), \\
z_{m+1}=y_{m}+z_{m}.
\end{array}\right.
$$

Adding the above three equations, we get
$$
\begin{aligned}
x_{m+1}+y_{m+1}+z_{m+1}= & (n-1)\left(x_{m}+y_{m}+z_{m}\right)+ \\
& (n-2)\left(x_{m-1}+y_{m-1}+z_{m-1}\right),
\end{aligned}
$$

which simplifies to
$$
S_{m+1}=(n-1) S_{m}+(n-2) S_{m-1}.
$$

It is easy to see that $S_{1}=n$ and $S_{2}=n^{2}-2$. The characteristic equation of (1) is $t^{2}-(n-1) t-(n-2)=0$, with characteristic roots $t_{1,2}=\frac{n-1 \pm \sqrt{n^{2}+2 n-7}}{2}$. Therefore,
$$
S_{m}=A \cdot\left(\frac{n-1+\sqrt{n^{2}+2 n-7}}{2}\right)^{m}+B \cdot\left(\frac{n-1-\sqrt{n^{2}+2 n-7}}{2}\right)^{m},
$$

where $A$ and $B$ are determined by
$$
\left\{\begin{array}{l}
S_{1}=A \cdot\left(\frac{n-1+\sqrt{n^{2}+2 n-7}}{2}\right)+B \cdot\left(\frac{n-1-\sqrt{n^{2}+2 n-7}}{2}\right)=n, \\
S_{2}=A \cdot\left(\frac{n-1+\sqrt{n^{2}+2 n-7}}{2}\right)^{2}+B \cdot\left(\frac{n-1-\sqrt{n^{2}+2 n-7}}{2}\right)^{2}=n^{2}-2
\end{array}\right.
$$

Solving the above system of equations, we get
$$
A=\frac{1+\frac{n+1}{\sqrt{n^{2}+2 n-7}}}{2}, B=\frac{1-\frac{n+1}{\sqrt{n^{2}+2 n-7}}}{2},
$$

Thus,
$$
\begin{array}{l}
S_{m}=\left(\frac{1+\frac{n+1}{\sqrt{n^{2}+2 n-7}}}{2}\right)\left(\frac{n-1+\sqrt{n^{2}+2 n-7}}{2}\right)^{m}+ \\
\left(\frac{1-\frac{n+1}{\sqrt{n^{2}+2 n-7}}}{2}\right)\left(\frac{n-1-\sqrt{n^{2}+2 n-7}}{2}\right)^{m}.
\end{array}
$$

Next, we subtract those that satisfy (1) but not (2).
If $a_{1}, a_{2}, \cdots, a_{m}$ are all the same, i.e., $a_{1}=\cdots=a_{m}=k \in\{1,2, \cdots, n\}$, there are $n$ such $\left(a_{1}, a_{2}, \cdots, a_{m}\right)$ (for $n \geqslant 3$);

If $a_{1}, a_{2}, \cdots, a_{m}$ contain exactly two different numbers, there are $\mathrm{C}_{n}^{2}$ ways to choose these two numbers, but we cannot choose $\{1, n\}$, so there are $\mathrm{C}_{n}^{2}-1$ ways to choose. Such $\left(a_{1}, a_{2}, \cdots, a_{m}\right)$ have $\left(\mathrm{C}_{n}^{2}-1\right)\left(2^{m}-2\right)$ possibilities.
In summary,
$$
\begin{aligned}
\left|B_{n}^{m}\right|= & S_{m}-n-\left(\mathrm{C}_{n}^{2}-1\right)\left(2^{m}-2\right) \\
= & \left(\frac{1+\frac{n+1}{\sqrt{n^{2}+2 n-7}}}{2}\right)\left(\frac{n-1+\sqrt{n^{2}+2 n-7}}{2}\right)^{m}+ \\
& \left(\frac{1-\frac{n+1}{\sqrt{n^{2}+2 n-7}}}{2}\right)\left(\frac{n-1-\sqrt{n^{2}+2 n-7}}{2}\right)^{m}- \\
& n-\left(\mathrm{C}_{n}^{2}-1\right)\left(2^{m}-2\right) \quad (n, m \geqslant 3).
\end{aligned}
$$

In particular, when $n=6$ and $m=3$,
$$
S_{3}=5 S_{2}+4 S_{1}=5 \times 34+4 \times 6=194,
$$

so
$$
\left|B_{6}^{3}\right|=194-6-\left(\mathrm{C}_{6}^{2}-1\right)\left(2^{3}-2\right)=104.
$$