Sonos in HA

I have an issue with HA and Sonos. Say I have 4 speakers A, B , C and D

B and C are normally paired together but it could also be B and D. , I run an automation that when A plays, pair with B and whatever speaker B is already paired with - either C or D. But I can’t get this automation to work. When I use the join function in HA to pie A and B( when A starts playing) , B abandons the speaker it was previously paired with, so I just get A and B

How can I pair A and B and whatever other speaker B is currently paired with? I asked ChatGPT for the yaml but that didn’t work

The join function joins a slave speaker to a master.
Slave of a Slave is not an option.

You have to be a bit creative then.
Either pair A with B and change the music for the group or read what is paired with B and the pair B with A and pair what B was paired to A also.