"Math Day" problem is only passing 1 out of 5 test cases

Sir I tried my best to solve the question but its only passing one of the 5 test cases. Please rectify where am I doing wrong.
The link for the code is :-

I am giving you hint:

use the property (a)^(x*y) = ((a^)^x)^y

and use fast exponentiation for calculating power.