Magnesium metal can be used to distinguish between an acid and a base by observing the reaction of magnesium with the given liquid.
Magnesium reacts with acids and dissolves in them to form solutions containing the aquated Mg (II) ion together with hydrogen gas, H2. For example with H2SO4 and HCl the reaction of Magnesium is as follows:
Mg(s) + H2SO4(aq) → Mg2+(aq) + SO42-(aq) + H2(g)
Mg(s) + 2HCl(aq) → Mg2+(aq) + 2Cl-(aq) + H2(g)
Magnesium does not react with dilute bases.
So if hydrogen is produced and the magnesium dissolves in the liquid you are testing it is an acid and if it does not react the liquid is a base.