You can change the frequent flyer number for earning prior to each flight. Make sure you get a new printed boarding pass so that you can send it in if there is a problem crediting the flight.
Alternatively, if you don't have status in any of the airline programmes and are not using your frequent flyer number to gain benefits such as lounge access, you can just put no frequent flyer number at all and apply for retro-credit after flying. This presumes you're already a member of both programmes.
You may be able to change your frequent flyer number at a ticketing kiosk, in the lounge, at the gate, or at an airline ticketing desk and in some cases you can do this online, but this may not be reliable very close to departure.