Solution (source code)

= Solution

Write $q=P_{BI}$ and $p=P_{AI}=1-q$. A path with $n$ visits to $I$ makes $n-1$ unsuccessful excursions back to $B$, followed by one successful step to $A$. Every $B\to I$ step has <probability> one, so
$$
\boxed{\Pr(N=n)=q^{n-1}p,\qquad n=1,2,\ldots.}
$$
The visit count has a <geometric distribution>, with success meaning the final $I\to A$ step.