#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll L,a,b,mod;
struct Matric
{
    ll a[3][3];
    Matric(){memset(a,0,sizeof(a));}
    Matric operator*(const Matric&o)const
    {
        Matric ans;
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
                for(int k=0;k<3;k++)
                {
                    ans.a[i][j]=(ans.a[i][j]+a[i][k]*o.a[k][j]%mod)%mod;
                }
        return ans;
    }
};
Matric Mqpow(Matric a,ll n)
{
    Matric base=a;
    Matric ans;
    ans.a[0][0]=1,ans.a[1][1]=1,ans.a[2][2]=1;
    while(n)
    {
        if(n&1)
            ans=ans*base;
        base=base*base;
        n>>=1;
    }
    return ans;
}
ll qpow(ll a,ll n)
{
    ll base=a;
    ll ans=1;
    while(n)
    {
        if(n&1)
            ans=ans*base%mod;
        base=base*base%mod;
        n>>=1;
    }
    return ans;
}
int getlen(ll x)
{
    int ans=0;
    while(x)
    {
        x/=10;
        ans++;
    }
    return ans;
}
ll getpos(int x)
{
    ll l=1,r=L,ans=1;;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(getlen(a+b*(m-1))<=x) l=m+1,ans=m;
        else r=m-1;
    }
    return ans;
}
int main()
{
    scanf("%lld%lld%lld%lld",&L,&a,&b,&mod);
    ll ans=a%mod;
    ll res=a%mod;
    ll now=1;
    for(int i=1;i<=18;i++)
    {
        ll p=getpos(i);
        if(p==now) continue;
        Matric A;
        A.a[0][0]=qpow(10,i),A.a[0][1]=1,A.a[0][2]=1;
        A.a[1][1]=1,A.a[1][2]=1,A.a[2][2]=1;
        A=Mqpow(A,p-now);
        ans=(A.a[0][0]*ans%mod+A.a[0][1]*res%mod+b%mod*A.a[0][2]%mod)%mod;
        res=(res+b%mod*(p-now)%mod)%mod;
        now=p;
    }
    printf("%lld\n",ans);
    return 0;
}
