Yet another thought:
Replacing by C the second occurrence of B that occurs in any line that contains A. (I think ex’s substitution command works only on the first occurrence or on all of them.)
Edit: not doable with :g, but doable with macros, I guess. My two previous suggestions do stand – at least I hope!