#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
//const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll mod;

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

vvl mul(vvl A,vvl B){
	vvl C(A.size(),vl(B[0].size()));
	for(int i=0;i<A.size();i++) for(int k=0;k<B.size();k++) for(int j=0;j<B[0].size();j++) (C[i][j]+=A[i][k]*B[k][j])%=mod;
	return C;
}

vvl pow(vvl A,ll n){
	vvl B(A.size(),vl(A.size()));
	for(int i=0;i<A.size();i++) B[i][i]=1;
	while(n>0){
		if(n&1) B=mul(B,A);
		A=mul(A,A);
		n>>=1;
	}
	return B;
}

ll n,a,d;

ll f(ll x){
	return a+d*x;
}

int main(){
	cin>>n>>a>>d>>mod;
	ll t=1,res=0,tmp=1;
	for(int i=0;i<17;i++) t*=10;
	for(int i=17;i>=0;i--){
		ll l=-1,r=n;
		while(r-l>1){
			ll m=(l+r)/2;
			if(f(m)>=t) r=m;
			else l=m;
		}
		ll A=f(r);
		l=-1,r=n;
		while(r-l>1){
			ll m=(l+r)/2;
			if(f(m)>=t*10) r=m;
			else l=m;
		}
		ll B=f(r);
		if(A<B){
			ll N=(B-A)/d;
			vvl a(3,vl(3));
			a[0][0]=t*10%mod;
			a[0][1]=a[1][1]=a[1][2]=a[2][2]=1;
			a=pow(a,N);
			ll sum=(A%mod*a[0][1]%mod+d%mod*a[0][2]%mod)%mod;
			(res+=sum*tmp)%=mod;
			(tmp*=Pow(Pow(10,N),i+1))%=mod;
		}
		t/=10;
	}
	cout<<res<<endl;
}