please help me in this question
I’ve not solved this problem, so I may be talking rubbish.
At the risk of stating the obvious, it sounds like it will involve modular matrix exponentiation. Perhaps Googling that will be enough to give you a start?