Electronic and magnetic states of Mn2 and Mn2H on Ag(111)