Hamilton takes pole in Hungary