5. Let the set
$$
\begin{aligned}
A= & \left\{\left(a_{1}, a_{2}, \cdots, a_{8}\right) \mid a_{i} \in \mathbf{Z}_{+}, 1 \leqslant a_{i} \leqslant\right. \\
& i+1 ; i=1,2, \cdots, 8\} .
\end{aligned}
$$

Let $X \subset A$, for any two different elements $\left(a_{1}, a_{2}, \cdots, a_{8}\right) 、\left(b_{1}, b_{2}, \cdots, b_{8}\right) \in X$, if there exist at least three different $i$ such that $a_{i} \neq b_{i}$, then $X$ is called a "good set". Find the maximum number of elements in a good set that is a subset of $A$.
Let set $X$ be a good set.
$$
\text { Let }\left(a_{1}, a_{2}, \cdots, a_{8}\right) \in X \text {, and call }\left(a_{1}, a_{2}, \cdots, a_{6}\right)
$$

the characteristic element of $\left(a_{1}, a_{2}, \cdots, a_{8}\right)$.
Since all characteristic elements of the good set $X$ must be distinct, the number of elements in the good set $X$ is also the number of all characteristic elements.
It is known that there are at most
$$
2 \times 3 \times 4 \times 5 \times 6 \times 7=5040
$$

characteristic elements, thus, $|X| \leqslant 5040$.
Finally, it is shown that there exists a good set $X \subset A$ such that
$$
|X|=5040 .
$$