Stability of Z-strings in strong magnetic fields