I find it impossible to properly follow two dissimilar tunes at the same time, or to imagine one tune while physically hearing another. So my trick for banishing earworms is to find something else to physically listen to, and then actively engage with trying to sustain the earworm. Lean into it, try to imagine the earworm in full detail, while the ears are telling the brain "hey, process this"
It usually does the trick. I think that trying to engage the earworm activates certain neurons that sustain it, but the imperative of actual sensory input competing for those same neurons disrupts the pattern that's gotten stuck. YMMV