#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long
class ThreeDigits{
public: bool checkzero=false;
public:
ll power(ll x,ll y,ll mod){
if(y<=0) return 1;
ll z=power(x,y/2,mod);
if(y%2){
if((z*z)>= mod || (z*z*x)>=mod) checkzero=true;
return (((z*z)%mod)*x)%mod;
}
else {
if((z*z)>= mod) checkzero=true;
return (z*z)%mod;
}
}
public:
string calculate(int X, int Y, int Z) {
checkzero=false;
ll n1=X,y=Y,z=Z;
ll res=power(n1,y,z*1000LL);
long double ans=(res*1.0)/z;
string x=to_string(ans);
int idx=1;
rep(i,0,x.length()) if(x[i]=='.') {idx=i;break;}
string final_ans="";
if(checkzero) rep(i,0,3-idx) final_ans+="0";
rep(i,0,idx+4) final_ans+=x[i];
// cout<<final_ans<<endl;
return final_ans;
}
void print(){
cout<<calculate(3,5,7)<<endl;
cout<<calculate(4,7,32)<<endl;
cout<<calculate(3,2,36)<<endl;
cout<<calculate(7,4,47)<<endl;
cout<<calculate(13,6,479)<<endl;
cout<<calculate(1234,56789,123456)<<endl;
cout<<calculate(999999999,128,1000000)<<endl;
}
};
int main(){
//freopen("input.txt", "r", stdin); // redirects standard input
//freopen("output1.txt", "w", stdout); // redirects standard output
ThreeDigits obj;
obj.print();
//int t;
//cin>>t;
//while(t--){
// int x,y,z;
// cin>>x>>y>>z;
// cout<<obj.calculate(x,y,z)<<endl;
//}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgcmVwKGksYSxiKSBmb3IoaW50IGk9YTtpPGI7aSsrKQojZGVmaW5lIGxsIHVuc2lnbmVkIGxvbmcgbG9uZwpjbGFzcyBUaHJlZURpZ2l0c3sKICBwdWJsaWM6IGJvb2wgY2hlY2t6ZXJvPWZhbHNlOwogIHB1YmxpYzoKICAgIGxsIHBvd2VyKGxsIHgsbGwgeSxsbCBtb2QpewogICAgICBpZih5PD0wKSByZXR1cm4gMTsKICAgICAgbGwgej1wb3dlcih4LHkvMixtb2QpOwogICAgICBpZih5JTIpewogICAgICAgIGlmKCh6KnopPj0gbW9kIHx8ICh6KnoqeCk+PW1vZCkgIGNoZWNremVybz10cnVlOwogICAgICAgIHJldHVybiAoKCh6KnopJW1vZCkqeCklbW9kOwogICAgICB9CiAgICAgIGVsc2UgewogICAgICAgIGlmKCh6KnopPj0gbW9kKSBjaGVja3plcm89dHJ1ZTsKICAgICAgICByZXR1cm4gKHoqeiklbW9kOwogICAgICB9CiAgICB9CiAgcHVibGljOgogICAgc3RyaW5nIGNhbGN1bGF0ZShpbnQgWCwgaW50IFksIGludCBaKSB7CiAgICAgIGNoZWNremVybz1mYWxzZTsKICAgICAgbGwgbjE9WCx5PVksej1aOwogICAgICBsbCByZXM9cG93ZXIobjEseSx6KjEwMDBMTCk7CiAgICAgIGxvbmcgZG91YmxlIGFucz0ocmVzKjEuMCkvejsKICAgICAgc3RyaW5nIHg9dG9fc3RyaW5nKGFucyk7CiAgICAgIGludCBpZHg9MTsKICAgICAgcmVwKGksMCx4Lmxlbmd0aCgpKSBpZih4W2ldPT0nLicpIHtpZHg9aTticmVhazt9CiAgICAgIHN0cmluZyBmaW5hbF9hbnM9IiI7CiAgICAgIGlmKGNoZWNremVybykgcmVwKGksMCwzLWlkeCkgZmluYWxfYW5zKz0iMCI7CiAgICAgIHJlcChpLDAsaWR4KzQpIGZpbmFsX2Fucys9eFtpXTsKICAgICAgLy8gY291dDw8ZmluYWxfYW5zPDxlbmRsOwoJCSAgcmV0dXJuIGZpbmFsX2FuczsKCSAgfQogICB2b2lkIHByaW50KCl7CiAgICAgY291dDw8Y2FsY3VsYXRlKDMsNSw3KTw8ZW5kbDsKICAgICBjb3V0PDxjYWxjdWxhdGUoNCw3LDMyKTw8ZW5kbDsKICAgICBjb3V0PDxjYWxjdWxhdGUoMywyLDM2KTw8ZW5kbDsKICAgICBjb3V0PDxjYWxjdWxhdGUoNyw0LDQ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