快速幂
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
LL quickPow(LL a,LL k, LL p){ // a ^ k mod p
LL res = 1;
while (k) {
if (k & 1) res = res * a % p;
k >>= 1;
a = a * a % p;
}
return res;
}
int main()
{
int N;
LL a,k,p;
scanf("%d",&N);
while (N--) {
scanf("%lld%lld%lld",&a,&k,&p);
printf("%lld\n",quickPow(a,k,p));
}
return 0;
}