#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int M;
int const MSIZE = 4;
using matrix = int[MSIZE][MSIZE];

inline int madd(int x,int y) {
	if (x+y<M) return x+y; else return x+y-M;
}
inline int msub(int x,int y) {
	if (x-y>=0) return x-y; else return x-y+M;
}
inline int mmul(int x,int y) {
	return int(ll(x)*y % M);
}

void matmul(matrix &res, const matrix &A, const matrix &B,
            int n, int p, int m) {  // res[n x m] = A[n x p] * B[p x m]
	static matrix tmp;
	rep(i,0,n) rep(j,0,m) tmp[i][j]=0;
	rep(i,0,n) rep(j,0,m) rep(k,0,p) {
		tmp[i][j]=madd(tmp[i][j], mmul(A[i][k],B[k][j]));
	}
	rep(i,0,n) rep(j,0,m) res[i][j]=tmp[i][j];
}

void matpow(ll pow, matrix &res, const matrix &A,
            int n, int m) {  // res[n x m] = res[n x m] * (A[m x m]^pow)
	static matrix tmp;
	rep(i,0,m) rep(j,0,m) tmp[i][j]=A[i][j];

	while (pow>0) {
		if (pow%2) matmul(res,res,tmp,n,m,m);
		matmul(tmp,tmp,tmp,m,m,m);
		pow/=2;
	}
}


int len(ll x) {
	assert(x>0);
	int res=0;
	while (x>0) {
		x/=10;
		res++;
	}
	return res;
}

ll find_len(ll S0,ll L,ll B) {
	int z=len(S0);
	ll l=0,r=L;
	while (l<r) {
		ll m=l+(r-l)/2;
		ll Sm=S0-B*m;
		if (z==len(Sm)) l=m+1; else r=m;
	}
	return l;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	ll L,A,B;
	cin>>L>>A>>B>>M;
	
	ll S0=A+B*(L-1);
	int pp=1;
	int res=0;
	while (L>0) {
		ll k=find_len(S0,L,B);
		ll z=len(S0);
//~ cerr<<z<<" "<<k<<" "<<S0<<" "<<pp<<endl;
		int z10=1;
		rep(i,0,z) z10=mmul(z10,10);
//~ cerr<<z10<<endl;
		
		int a0=int((S0-B*(k-1))%M);
		int b0=int(ll(a0)*pp % M);
//~ cerr<<a0<<" "<<b0<<endl;
		matrix r={{int(B%M), a0, b0, z10},};
		matrix X={
			{1, 1,    pp,   0},
			{0, 1,    pp,   0},
			{0, 0,   z10,   0},
			{0, 0,     0, z10},
		};
		
		matpow(k-1,r,X,1,4);
		res=madd(res,r[0][2]);
//~ cerr<<res<<endl;
		
		L-=k;
		S0=S0-B*k;
		pp=mmul(pp,r[0][3]);
	}
	
	cout<<res<<"\n";
}
