I would probably replace both simultaneously, particularly if the patient has symptomatic hypokalemia such as cardiac arrhythmias and/or respiratory muscle weakness. That said, in the absence of symptoms, it makes theoretical sense to replace Mg++ first since intracellular Mg++ is responsible for preventing the efflux K+ through its binding to the intracellular domain of the ROMK channel in the cortical collecting duct of the nephron.
See the following paper: https://jasn.asnjournals.org/content/18/10/2649
I would check serum calcium levels , as hypomagnesemia can cause hypokalemia & hypocalcemia . If low , I would treat hypomagnesemia first . Hyomagnesemia , hypokalemia & hypocalemia can occur together .Hypomagnesemia can cause decreased sensitivity to PTH & cause hypocalcemia .