Confused In Modular Exponentiation

I get that what I need to do in question but I am unable to figure out what am I doing wrong in my solution can someone please give some hint.

@Prakhar2810
You are doing a mathematical mistake:

(a1 + a2 + a3) % m = (((a1 % m) + (a2 % m)) % m + (a3 % m)) % m;

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.