Solution (source code)

= Solution
{c}

In each trial the presence indicators of $A$ and $B$ are independent <Bernoulli random variables>, with probabilities $p$ and $r$. Independence across trials makes their two entire indicator sequences independent. Let $N$ be the number of trials before the first $A$; then $N\sim\operatorname{Geom}_0(p)$. Among these $N$ preceding trials, the $B$ indicators are independent with probability $r$.

Thus the count is the <random sum> from part <5/b/i>, and
$$
\boxed{\text{count}\sim\operatorname{Geom}_0\!\left(\frac p{p+(1-p)r}\right).}
$$
An $AB$ outcome on the stopping trial contributes nothing, because the question counts only outcomes strictly before the first $A$.