How to purge cleaner filament before and after via AMS?

So let’s say spool 1 and 2 are similar, will be printed, then if I use spool 3, I want to run spool 4 which is cleaner filament, before spool 3 and after spool 3.
I think I can do this via filament startup/end code via gcode, but what’s the variable to use different AMS bays or AMS spool number, not sure what to call it.
How to extrude x amount of A4 with gcode?
It may be too late tonight and I just need sleep but it’s not coming to me atm lol…