Laser cooling of Mg and Ca atomic beams