Mike and HashTrick Problem

I am getting a TLE in two test cases.