Hamilton seals hat-trick in Shanghai