Regarding concept in lights new car

ques link https://hack.codingblocks.com/contests/c/473/92

in this we actually had to compute { A ^ (B%(p-1)) }%p but sir has rewritten this expression

as (A%p) ^ (B%(p-1)) . i am not able to understand how { A ^ (B%(p-1)) }%p has got converted to

(A%p) ^ (B%(p-1))

This follows from simple Modulo Properties. Check this for more explanation.