Ambiguous grammar to equivalent unambiguous grammar
As you have observed, the only problem in the original CFG is that the string $ab$ can be generated by both $A$ and $B$.

Here is a hint. Instead of generating $ab, a^2b^2, a^3b^3,\cdots$, can you let $A$ generate $a^2b^2, a^3b^3,\cdots$ without generating $ab$?