Model marbel toy with finite automata
Count $A$'s and $B$'s. The next $A$ will only exit at $D$ iff the first two levers are in right position. When does that happen? The first lever toggles at every $A$, but the second lever interacts with the $B$'s.

At the same time, the situation for $B$ is symmetric. The next $B$ will not exit $D$ only if both levers are left. When does that happen?