#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mm,mod;
struct matran{
ll a[2][2];
void print(){
for(ll i=0;i<2;i++){
for(ll j=0;j<2;j++) cout<<a[i][j]<<" ";
cout<<'\n';
}
}
};
matran mot;
struct cap{
ll u,u_plus_1;
void print(){
cout<<u<<" "<<u_plus_1<<'\n';
}
};
ll f(ll a,ll n, ll MOD){
ll res=a,ans=0;
while(n){
if(n%2) ans = (ans+res)%MOD;
res=(res+res)%MOD;
n/=2;
}
return ans;
}
ll po1(ll a,ll n, ll MOD){
ll res=a,ans=1;
while(n){
if(n%2) ans=ans*res%MOD;
res=res*res%MOD;
n/=2;
}
return ans;
}
matran prod(matran A,matran B){
matran anss;
anss.a[0][0]=(f(A.a[0][0],B.a[0][0],mod) + f(A.a[0][1],B.a[1][0],mod))%mod;
anss.a[0][1]=(f(A.a[0][0],B.a[0][1],mod) + f(A.a[0][1],B.a[1][1],mod))%mod;
anss.a[1][0]=(f(A.a[1][0],B.a[0][0],mod) + f(A.a[1][1],B.a[1][0],mod))%mod;
anss.a[1][1]=(f(A.a[1][0],B.a[0][1],mod) + f(A.a[1][1],B.a[1][1],mod))%mod;
return anss;
}
matran po(matran X,ll n){
matran res = X, ans = mot;
while(n){
if(n%2) ans = prod(ans,res);
res = prod(res,res);
n/=2;
}
return ans;
}
cap prod1(cap pp, matran X){
cap ans;
ans.u = (f(pp.u,X.a[0][0],mod)+f(pp.u_plus_1,X.a[1][0],mod))%mod;
ans.u_plus_1 = (f(pp.u,X.a[1][0],mod)+f(pp.u_plus_1,X.a[1][1],mod))%mod;
return ans;
}
int main(){
// freopen("lala.inp","r",stdin);
// freopen("lala.out","w",stdout);
ll a,b,nn,xx,testcase;
// cin>>testcase;
testcase = 1;
for(ll qq=1;qq<=testcase;qq++){
// cin>>a>>b;
cin>>xx>>nn>>mm;
mod = mm;
ll p,q,len;
len = to_string(xx).size();
p=po1(10,len,mm);
q=xx%mm;
cap init;
init.u = q;
init.u_plus_1 = 1;
matran M;
M.a[0][0]=p;
M.a[0][1]=0;
M.a[1][0]=q;
M.a[1][1]=1;
mot.a[0][0]=1;
mot.a[0][1]=0;
mot.a[1][0]=0;
mot.a[1][1]=1;
matran res = po(M,nn-1);
cap ansss = prod1(init,res);
cout<<ansss.u<<'\n';
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcKbGwgbW0sbW9kOwpzdHJ1Y3QgbWF0cmFuewogICAgbGwgYVsyXVsyXTsKICAgIHZvaWQgcHJpbnQoKXsKICAgICAgICAgICAgZm9yKGxsIGk9MDtpPDI7aSsrKXsKICAgICAgICAgICAgICAgICAgICBmb3IobGwgaj0wO2o8MjtqKyspIGNvdXQ8PGFbaV1bal08PCIgIjsKICAgICAgICAgICAgICAgICAgICBjb3V0PDwnXG4nOwogICAgICAgICAgICB9CiAgICB9Cn07Cm1hdHJhbiBtb3Q7CnN0cnVjdCBjYXB7CiAgIGxsIHUsdV9wbHVzXzE7CiAgIHZvaWQgcHJpbnQoKXsKICAgICAgICAgICBjb3V0PDx1PDwiICI8PHVfcGx1c18xPDwnXG4nOwogICB9Cn07CmxsIGYobGwgYSxsbCBuLCBsbCBNT0QpewogICAgICAgIGxsIHJlcz1hLGFucz0wOwogICAgICAgIHdoaWxlKG4pewogICAgICAgICAgICAgICAgaWYobiUyKSBhbnMgPSAoYW5zK3JlcyklTU9EOwogICAgICAgICAgICAgICAgcmVzPShyZXMrcmVzKSVNT0Q7CiAgICAgICAgICAgICAgICBuLz0yOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYW5zOwp9CmxsIHBvMShsbCBhLGxsIG4sIGxsIE1PRCl7CiAgICAgICAgbGwgcmVzPWEsYW5zPTE7CiAgICAgICAgd2hpbGUobil7CiAgICAgICAgICAgICAgICBpZihuJTIpIGFucz1hbnMqcmVzJU1PRDsKICAgICAgICAgICAgICAgIHJlcz1yZXMqcmVzJU1PRDsKICAgICAgICAgICAgICAgIG4vPTI7CiAgICAgICAgfQogICAgICAgIHJldHVybiBhbnM7Cn0KbWF0cmFuIHByb2QobWF0cmFuIEEsbWF0cmFuIEIpewogICAgICAgIG1hdHJhbiBhbnNzOwogICAgICAgIGFuc3MuYVswXVswXT0oZihBLmFbMF1bMF0sQi5hWzBdWzBdLG1vZCkgKyBmKEEuYVswXVsxXSxCLmFbMV1bMF0sbW9kKSklbW9kOwogICAgICAgIGFuc3MuYVswXVsxXT0oZihBLmFbMF1bMF0sQi5hWzBdWzFdLG1vZCkgKyBmKEEuYVswXVsxXSxCLmFbMV1bMV0sbW9kKSklbW9kOwogICAgICAgIGFuc3MuYVsxXVswXT0oZihBLmFbMV1bMF0sQi5hWzBdWzBdLG1vZCkgKyBmKEEuYVsxXVsxXSxCLmFbMV1bMF0sbW9kKSklbW9kOwogICAgICAgIGFuc3MuYVsxXVsxXT0oZihBLmFbMV1bMF0sQi5hWzBdWzFdLG1vZCkgKyBmKEEuYVsxXVsxXSxCLmFbMV1bMV0sbW9kKSklbW9kOwogICAgICAgIHJldHVybiBhbnNzOwp9Cm1hdHJhbiBwbyhtYXRyYW4gWCxsbCBuKXsKICAgICAgICBtYXRyYW4gcmVzID0gWCwgYW5zID0gbW90OwogICAgICAgIHdoaWxlKG4pewogICAgICAgICAgICAgICAgaWYobiUyKSBhbnMgPSBwcm9kKGFucyxyZXMpOwogICAgICAgICAgICAgICAgcmVzID0gcHJvZChyZXMscmVzKTsKICAgICAgICAgICAgICAgIG4vPTI7CiAgICAgICAgfQogICAgICAgIHJldHVybiBhbnM7Cn0KY2FwIHByb2QxKGNhcCBwcCwgbWF0cmFuIFgpewogICAgICAgIGNhcCBhbnM7CiAgICAgICAgYW5zLnUgPSAoZihwcC51LFguYVswXVswXSxtb2QpK2YocHAudV9wbHVzXzEsWC5hWzFdWzBdLG1vZCkpJW1vZDsKICAgICAgICBhbnMudV9wbHVzXzEgPSAgKGYocHAudSxYLmFbMV1bMF0sbW9kKStmKHBwLnVfcGx1c18xLFguYVsxXVsxXSxtb2QpKSVtb2Q7CiAgICAgICAgcmV0dXJuIGFuczsKfQppbnQgbWFpbigpewogICAgICAgIC8vIGZyZW9wZW4oImxhbGEuaW5wIiwiciIsc3RkaW4pOwogICAgICAgIC8vIGZyZW9wZW4oImxhbGEub3V0IiwidyIsc3Rkb3V0KTsKCiAgICAgICAgbGwgYSxiLG5uLHh4LHRlc3RjYXNlOwogICAgICAgIC8vIGNpbj4+dGVzdGNhc2U7CiAgICAgICAgdGVzdGNhc2UgPSAxOwogICAgICAgIGZvcihsbCBxcT0xO3FxPD10ZXN0Y2FzZTtxcSsrKXsKICAgICAgICAvLyAgY2luPj5hPj5iOwogICAgICAgIGNpbj4+eHg+Pm5uPj5tbTsKICAgICAgICBtb2QgPSBtbTsKICAgICAgICBsbCBwLHEsbGVuOwogICAgICAgIGxlbiA9IHRvX3N0cmluZyh4eCkuc2l6ZSgpOwogICAgICAgIHA9cG8xKDEwLGxlbixtbSk7CiAgICAgICAgcT14eCVtbTsKICAgICAgICBjYXAgaW5pdDsKICAgICAgICBpbml0LnUgPSBxOwogICAgICAgIGluaXQudV9wbHVzXzEgPSAxOwogICAgICAgIG1hdHJhbiBNOwogICAgICAgIE0uYVswXVswXT1wOwogICAgICAgIE0uYVswXVsxXT0wOwogICAgICAgIE0uYVsxXVswXT1xOwogICAgICAgIE0uYVsxXVsxXT0xOwogICAgICAgIG1vdC5hWzBdWzBdPTE7CiAgICAgICAgbW90LmFbMF1bMV09MDsKICAgICAgICBtb3QuYVsxXVswXT0wOwogICAgICAgIG1vdC5hWzFdWzFdPTE7CiAgICAgICAKICAgICAgICBtYXRyYW4gcmVzID0gcG8oTSxubi0xKTsKICAgICAgICBjYXAgYW5zc3MgPSBwcm9kMShpbml0LHJlcyk7CiAgICAgICAgY291dDw8YW5zc3MudTw8J1xuJzsKICAgCiAgICAgICAgfQoKfQ==