22. Let $n$ be any positive integer, in a sequence containing only the letters $\mathrm{A}$ and $\mathrm{B}$, at most three $\mathrm{A}$'s are adjacent, and at most three $\mathrm{B}$'s are adjacent. Let $S(n)$ denote the number of $n$-term subsequences in the sequence. Then the remainder when $S(2015)$ is divided by 12 is ( ).
(A) 0
(B) 4
(C) 6
(D) 8
(E) 10
22. D.

Let $A(n)$ denote the number of sequences with $n$ terms, where the last term is A; let $B(n)$ denote the number of sequences with $n$ terms, where the last term is B. Then,
$$
S(n)=A(n)+B(n) \text {, and } A(n)=B(n) \text {. }
$$

Thus, $S(n)=2 A(n)$.
For a sequence of $n$ terms ending with A, it can always be decomposed into sequences of $n-1$, $n-2$, and $n-3$ terms ending with B. Hence,
$$
\begin{array}{l}
A(n)=B(n-1)+B(n-2)+B(n-3) \\
=A(n-1)+A(n-2)+A(n-3) .
\end{array}
$$

Consider the sequence formed by $A(n)$:
$$
1,1,2,4,7,13,24, \cdots,
$$

where $A(0)$ is the first term, and it is defined that $A(0)=1$.
Notice that, the remainder of $S(2015)$ when divided by 12 is the same as the remainder of $A(2015)$ when divided by 6.
Consider the sequence of remainders of $A(n)$ modulo 2:
$1,1,0,0,1,1,0,0, \cdots$.
Then $A(n)$ is a periodic sequence modulo 2, with period $T=4$,
$$
A(2015)=A(3) \equiv 0(\bmod 2) \text {. }
$$

Now consider the sequence of remainders of $A(n)$ modulo 3:
$$
1,1,2,1,1,1,0,2,0,2,1,0,0,1,1,2, \cdots \text {. }
$$

Then $A(n)$ is a periodic sequence modulo 3, with period $T=13$,
$$
A(2015)=A(0) \equiv 1(\bmod 3) \text {. }
$$

Therefore, $A(2015) \equiv 4(\bmod 6)$,
$$
S(2015) \equiv 8(\bmod 12)
$$