12. (18 points) Let $S$ be a set of distinct quadruples $\left(a_{1}, a_{2}, a_{3}, a_{4}\right)$, where $a_{i}=0$ or 1 $(i=1,2,3,4)$. It is known that the number of elements in $S$ does not exceed 15, and satisfies:
if $\left(a_{1}, a_{2}, a_{3}, a_{4}\right) 、\left(b_{1}, b_{2}, b_{3}, b_{4}\right) \in S$, then $\left(c_{1}, c_{2}, c_{3}, c_{4}\right) 、\left(d_{1}, d_{2}, d_{3}, d_{4}\right) \in S$,

where, $c_{i}=\max \left\{a_{i}, b_{i}\right\}, d_{i}=\min \left\{a_{i}, b_{i}\right\}(i=1,2,3,4)$. Find the maximum number of elements in the set $S$.
12. Clearly, there are 16 possible quadruples. Since at least one quadruple is not in $S$, it follows that $(1,0,0,0)$, $(0,1,0,0)$, $(0,0,1,0)$, $(0,0,0,1)$ must have at least one that is not in $S$. Otherwise, by the given conditions, all quadruples would be in $S$.
Assume $(1,0,0,0) \notin S$.
In this case, by the given conditions,
$(1,1,0,0)$, $(1,0,1,0)$, $(1,0,0,1)$

at least two of these cannot be in $S$ (assume $(1,1,0,0)$ and $(1,0,1,0)$ are not in $S$). Then $(1,1,1,0)$ and $(1,1,0,1)$ cannot both be in $S$ (assume $(1,1,1,0)$ is not in $S$). Therefore, the number of elements in $S$ is at most $16-4=12$.

Let $S$ be the set of all 16 possible quadruples after removing the above 4 quadruples.
Next, we prove by contradiction that $S$ satisfies the conditions of the problem.
Take any $\left(a_{1}, a_{2}, a_{3}, a_{4}\right)$, $\left(b_{1}, b_{2}, b_{3}, b_{4}\right) \in S$.
(1) If $\left(c_{1}, c_{2}, c_{3}, c_{4}\right) \notin S$, then $c_{1}=1$, $c_{4}=0$.
Thus, $1 \in \{a_{1}, b_{1}\}$, $a_{4}=b_{4}=0$.
Assume $a_{1}=1$, then $\left(a_{1}, a_{2}, a_{3}, a_{4}\right)$ is among the 4 quadruples removed, which is a contradiction.
(2) If $\left(d_{1}, d_{2}, d_{3}, d_{4}\right) \notin S$, then $d_{1}=1$, $d_{4}=0$.
Thus, $a_{1}=b_{1}=1$, $0 \in \{a_{4}, b_{4}\}$.
Assume $a_{4}=0$, then $\left(a_{1}, a_{2}, a_{3}, a_{4}\right)$ is among the 4 quadruples removed, which is a contradiction.