Hamilton beats the elements to seize pole in wet Hungary