I have an idea:

It seems to be P = (p-q)/(p+q). My argument is messy though.

Imagine there is a hidden sequence of voting which is randomly selection but effectively fixed, then the problem is selecting a starting point which doesn't lead to as many (or more) B votes coming out before A votes. If B's are sparsely distributed (no two consecutive B votes) then you just don't want to start at the B vote or at the the A vote immediately before it. There are p-q of these non-leading A votes and so that gives the proposed formula. When B votes are non-sparse (say there are two B votes in a row) then you just want to avoid the two leading A votes as your starting point. So the result would seem to be robust for the non-sparse case and I would argue general for any distribution. But I'm sure there must be a much cleaner combinatorial argument.