// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);

int __inf_ignore(){
	int t = inf<int>;
	return t;
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"print.hpp"
#include"debug.hpp"
#endif
// }}}

Int L;
Int A;
Int B;
Int M;

int MOD;

//{{{ modular algebra
struct Num{
	int v;
	int mod;
	template<class T>
	Num(T n){
		mod = MOD;
		v = n%mod;
		if(v<0)v+=mod;
	}
	Num():v(0){}
	explicit operator int() const {return v;}
	explicit operator long long() const {return v;}
	inline void operator *=(const Num &a) {
		v = (v*(long long)a.v)%mod;
	}
	inline Num operator *(const Num &a) {
		Num n(*this);n*=a;
		return n;
	}
	inline void operator+=(const Num &a){
		v+=a.v;
		if(v>=mod)v-=mod;
		//	assert(0<=v and v<mod);
	}
	inline Num operator+(const Num &a){
		Num n(*this);n+=a;
		return n;
	}
	inline Num operator -(){
		if(v==0)return 0;
		else return Num(mod-v);
	}
	inline void operator -=(const Num &a){
		v-=a.v;
		if(v<0)v+=mod;
	}
	inline Num operator -(const Num &a){
		Num n(*this);n-=a;
		return n;
	}
#ifdef __GCD_H
	inline Num inv(){
		return Num(invMod(this->v,mod));
	}
	inline void operator /=(const Num &a){
		(*this)*=invMod(a.v,mod);
	}
	inline Num operator /(const Num &a){
		Num n(*this);n/=a;
		return n;
	}
#endif
};

template<class T>
T& operator <<(T &os, const Num &n){
	os<<(int)n.v;
	return os;
}

template<class T>
T& operator >>(T &is, Num &n){
	long long v;is >> v;
	n = Num(v);
	return is;
}
//}}}
using Mint =  Num;

//{{{ Mpow(Num x,Int k)
/* (x^k)%m */
inline Num Mpow(Num x, Int k){
	if(k==0) return 1;
	Num res(Mpow(x,k/2));
	res*=res;
	if(k%2)res*=x;
	return res;
}
inline Num __Mpow(const Num &x, Int k){
	if(k==0) return 1;
	Num res(__Mpow(x,k/2));
	res*=res;
	if(k%2)res*=x;
	return res;
}
template<class T>
inline Num Mpow(T x, Int k){
	return Mpow(Num(x),k);
}
//}}}

//{{{ matrix library: MATRIX<T> A(n); MATRIX<T> A(n,m); VECTOR<T> v(n);
template<class T>
struct VECTOR:public vector<T>{
	int n;
	VECTOR(const int &n):n(n){
		this->assign(n,0);
	}
};

// O( n )
template<class T>
T inner_product(const VECTOR<T> &a, const VECTOR<T> &b) {
	T ans = 0;
	for (int i = 0; i < a.n; ++i)
		ans += a[i]*b[i];
	return ans;
}

template<class T>
struct MATRIX:vector<vector<T> > {
	int n,m;
	MATRIX(const int &n):n(n),m(n){
		this->assign(n,vector<T>(n,0));
	}
	MATRIX(const pair<int,int> &p):n(p.first),m(p.second){
		this->assign(n,vector<T>(m,0));
	}
	// O( n )
	void operator+=(const MATRIX<T> &B){
		REP(i,n)REP(j,m)(*this)[i][j] += B[i][j];
	}
	void operator-=(const MATRIX<T> &B){
		REP(i,n)REP(j,m)(*this)[i][j] -= B[i][j];
	}
};

template<class T>
MATRIX<T> identity(int n) {
	MATRIX<T> A(n);
	for (int i = 0; i < n; ++i) A[i][i] = 1;
	return A;
}

template<class T>
MATRIX<T> zero(int n) {
	MATRIX<T> A(n);
	return A;
}

template<class T>
MATRIX<T> operator+(const MATRIX<T> &A, const MATRIX<T> &B) {
	MATRIX<T> C{A};
	C+=B;
	return C;
}
template<class T>
MATRIX<T> operator-(const MATRIX<T> &A, const MATRIX<T> &B) {
	MATRIX<T> C{A};
	C-=B;
	return C;
}
// O( n^2 )
template<class T>
VECTOR<T> operator*(const MATRIX<T> &A, const VECTOR<T> &x) {
	VECTOR<T> y(A.n);
	for (int i = 0; i < A.n; ++i)
		for (int j = 0; j < A.m; ++j)
			y[i] += T(A[i][j])*x[j];
	return y;
}
// O( n^3 )
template<class T>
MATRIX<T> operator*(const MATRIX<T> &A, const MATRIX<T> &B) {
	MATRIX<T> C({A.n,B.m});
	for (int i = 0; i < C.n; ++i)
		for (int j = 0; j < C.m; ++j)
			for (int k = 0; k < A.m; ++k)
				C[i][j] += T(A[i][k])*B[k][j];
	return C;
}
// O( n^3 )
template<class T>
void operator*=(MATRIX<T> &A, const MATRIX<T> &B){
	A = A*B;
}

// O( n^3 log e )
template<class T>
MATRIX<T> pow(const MATRIX<T> &A, long long e) {
	return e == 0 ? identity<T>(A.size())  :
	e % 2 == 0 ? pow(A*A, e/2) : A*pow(A, e-1);
}

typedef int Number;
typedef MATRIX<Number> Matrix;
typedef VECTOR<Number> Vector;

//}}}

void solve(){
	MOD = M;
	Mint p = 1, ans = 0;
	for(int d = 18;d>=1;d--){
		Int Min = 1, Max = 1;
		REP(i,d)Max *= 10;
		Min = Max/10;
		if(Max - A - 1 < 0)continue;
		Int imin, imax = min(L-1,(Max - 1 - A)/B);
		if(Min - A>=0){
			imin = (Min - A + B - 1)/B;
		}else{
			imin = 0;
		}
		if(imin>imax)continue;
		MATRIX<Mint> A({3,3});
		A[0][0] = A[0][1] = 1;
		Mint k(Max);
		A[1][1] = A[2][2] = k;
		A[1][2] = - k * B;
		VECTOR<Mint> b(3);
		b[0] = 0;
		b[1] = ::A + ::B * imax;
		b[2] = 1;
		A = pow(A,imax-imin+1);
		b = A * b;
		ans += b[0] * p;
		p *= Mpow(k,imax - imin + 1);
	}
	cout<<(Int)ans<<endl;
}
//{{{ main fucnction
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> L;
	cin >> A;
	cin >> B;
	cin >> M;
	solve();
	return 0;
}
//}}}


Measured memory_bytes: 256