Solution (source code)

= Solution

Put $q=1-p$ and track the difference $S_n$ between the numbers of wins. It is a <biased random walk> with increments $+1$ and $-1$, stopped on first reaching $3$ or $-3$.

To finish at $+3$ on game five, there must be four wins for $A$ and one for $B$, with the final game won by $A$. The unique loss for $A$ can be in position one, two or three. If it were in position four or five, the first three games would already have stopped the contest. Each of the three allowed paths remains strictly inside the barriers until the last step and has <probability> $p^4q$. By interchanging players, there are also three paths ending at $-3$, each with <probability> $pq^4$. Therefore
$$
\boxed{\mathbb P(N=5)=3p^4q+3pq^4=3pq(p^3+q^3).}
$$
For a fair game this is $3/16$. Counting all five-game sequences with final win difference three would overcount paths on which the contest ended earlier.