What office did Ibn Sina receive in Hamadan?