Description:
Accept:
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
LL a, b, p, t, ans;
int f(LL x, LL y, LL m)
{
LL ret = 1;
for (; y; y = y / 2, x = 1LL * x * x % m)
{
if (y & 1)
ret = 1LL * ret * x % m;
}
return ret;
}
int main()
{
cin >> t;
while (t--)
{
cin >> a >> b >> p;
LL res = f(a, b, p);
cout << res<< endl;
}
return 0;
}