12. Let the integer sequence $a_{1}, a_{2}, \cdots, a_{k}$ have length $k$, where $1 \leqslant a_{i} \leqslant 4(i=1,2, \cdots$, $k)$. If the sequence satisfies the condition: “If $a_{i}=a_{j}$ and $a_{i+1}=a_{j+1}$, then $i=j$. “then the maximum value of $k$ is $\qquad$.
12. 17

Given that the different combinations of $\left(a_{i}, a_{i+1}\right)$ are $4 \times 4=16$. By the condition, the same combination cannot appear twice in the sequence (since $i \neq j$, then $a_{i} \neq a_{j}$ or $a_{i+1} \neq a_{j+1}$, i.e., $\left(a_{1}, a_{i+1}\right)$ and $\left(a_{3}, a_{s+1}\right)$ are different). Therefore, $k \leqslant 32-15=17$. For example, 11213142232433441 satisfies the requirement.