AMAZE. I. The evolution of the mass-metallicity relation at z > 3