Lewis Hamilton takes his first pole position for Ferrari and his first for more than three years at the Mexico City Grand Prix.