Please Review my code
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll pexp(ll a,ll i,ll p)
{
if(i==0)
{
return 1;
}
if(i==1)
{
return a;
}
if(i%2==1)
{
return ((a*(pexp(a,i-1,p)%p))%p);
}
else
{
ll x=(pexp(a,(i/2),p))%p;
return (((x)*(x))%p);
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t;
cin>>t;
while(t--)
{
ll a,n,p;
cin>>a>>n>>p;
a=a%p;
ll ans=a;
// cout<<a<<"a"<<endl;
for(ll i=2;i<=n;i++)
{
ll pe=pexp(ans,i,p);
ans=(ans*pe)%p;
// cout<<ans<<" "<<pe<<endl;
}
cout<<ans<<endl;
}
}