At the beginning of the experiment, you attempt to assign two different sounds to the same variable name: background_sound. Any variable name can only point to one thing at a time, so the second assignment will over write the first.
You can get around this by using two distinct variable names, e.g.
background_sound_A = sound.Sound(‘sound/A.wav’)
background_sound_B = sound.Sound(‘sound/B.wav’)
and use the appropriate name as required.
But now that I think about it, this would all probably work better if you could change the structure of your experiment to use nested loops instead of consecutive loops, but I guess that depends on whether there is any real difference between your Sgrouphh and Fgrouphl routines.
Lastly, to help make your posts readable please: