#include <bits/stdc++.h>
using namespace std;
 
#define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i)
 
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
 
#define LOWBIT(x) ((x)&(-x))
 
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define UNIQUE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define REMOVE(x, c) x.erase(remove(x.begin(), x.end(), c), x.end()); // 删去 x 中所有 c 
#define TOLOWER(x) transform(x.begin(), x.end(), x.begin(),::tolower);
#define TOUPPER(x) transform(x.begin(), x.end(), x.begin(),::toupper);
 
#define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a))

#define MP make_pair
#define PB push_back
#define ft first
#define sd second
 
template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
    in >> p.first >> p.second;
    return in;
}
 
template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
    for (auto &x: v)
        in >> x;
    return in;
}
 
template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]" << "\n";
    return out;
}

inline int gc(){
	static const int BUF = 1e7;
	static char buf[BUF], *bg = buf + BUF, *ed = bg;
	
	if(bg == ed) fread(bg = buf, 1, BUF, stdin);
	return *bg++;
} 

inline int ri(){
	int x = 0, f = 1, c = gc();
	for(; c<48||c>57; f = c=='-'?-1:f, c=gc());
	for(; c>47&&c<58; x = x*10 + c - 48, c=gc());
	return x*f;
}

template<class T>
inline string toString(T x) {
    ostringstream sout;
    sout << x;
    return sout.str();
}

inline int toInt(string s) {
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}

//min <= aim <= max
template<typename T>
inline bool BETWEEN(const T aim, const T min, const T max) {
	return min <= aim && aim <= max;
}
 
typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef pair< int, PII > PIPII;
typedef pair< string, int > PSI;
typedef pair< int, PSI > PIPSI;
typedef set< int > SI;
typedef set< PII > SPII;
typedef vector< int > VI;
typedef vector< double > VD;
typedef vector< VI > VVI;
typedef vector< SI > VSI;
typedef vector< PII > VPII;
typedef map< int, int > MII;
typedef map< int, string > MIS;
typedef map< int, PII > MIPII;
typedef map< PII, int > MPIII;
typedef map< string, int > MSI;
typedef map< string, string > MSS;
typedef map< PII, string > MPIIS;
typedef map< PII, PII > MPIIPII;
typedef multimap< int, int > MMII;
typedef multimap< string, int > MMSI;
//typedef unordered_map< int, int > uMII;
typedef pair< LL, LL > PLL;
typedef vector< LL > VL;
typedef vector< VL > VVL;
typedef priority_queue< int > PQIMax;
typedef priority_queue< int, VI, greater< int > > PQIMin;
const double EPS = 1e-8;
const LL inf = 0x7fffffff;
const LL infLL = 0x7fffffffffffffffLL;
LL mod = 1e9 + 7;
const int maxN = 1e5 + 7;
const LL ONE = 1;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555;

struct Matrix{
	int row, col;
	LL MOD;
	VVL mat;
	
	Matrix(int r, int c, LL p = mod) : row(r), col(c), MOD(p) { 
		mat.assign(r, VL(c, 0));
	}
	Matrix(const Matrix &x, LL p = mod) : MOD(p){
		mat = x.mat;
		row = x.row;
		col = x.col;
	}
	Matrix(const VVL &A, LL p = mod) : MOD(p){
		mat = A;
		row = A.size();
		col = A[0].size();
	}
	
	// x * 单位阵 
	inline void E(int x = 1) {
		assert(row == col);
		Rep(i, row) mat[i][i] = x;
	}
	
	inline VL& operator[] (int x) {
		assert(x >= 0 && x < row);
		return mat[x];
	}
	
	inline Matrix operator= (const VVL &x) {
		row = x.size();
		col = x[0].size();
		mat = x;
		return *this;
	}
	
	inline Matrix operator+ (const Matrix &x) {
		assert(row == x.row && col == x.col);
		Matrix ret(row, col);
		Rep(i, row) {
			Rep(j, col) {
				ret.mat[i][j] = mat[i][j] + x.mat[i][j];
				ret.mat[i][j] %= MOD;
			}
		}
		return ret;
	}
	
	inline Matrix operator* (const Matrix &x) {
		assert(col == x.row);
		Matrix ret(row, x.col);
		Rep(k, x.col) {
			Rep(i, row) {
				if(mat[i][k] == 0) continue;
				Rep(j, x.col) {
					ret.mat[i][j] += mat[i][k] * x.mat[k][j];
					ret.mat[i][j] %= MOD;
				}
			}
		}
		return ret;
	}
	
	inline Matrix operator*= (const Matrix &x) { return *this = *this * x; }
	inline Matrix operator+= (const Matrix &x) { return *this = *this + x; }
	
	inline void print() {
		Rep(i, row) {
			Rep(j, col) {
				cout << mat[i][j] << " ";
			}
			cout << endl;
		}
	}
};

// 矩阵快速幂，计算x^y 
inline Matrix mat_pow_mod(Matrix x, LL y) {
	Matrix ret(x.row, x.col);
	ret.E();
	while(y){
		if(y & 1) ret *= x;
        x *= x;
        y >>= 1;
	}
	return ret;
}

LL L, A, B, M, ans; 

// 从数列第 st 项开始，查找区间 [L, R]，使得区间内的所有数都小于 bit 大于等于 bit/10。 
// 有返回 true 没有返回 false 
LL st = 0, bit = 10, l, r;
bool getLR() {
	if(st >= L || A + st * B >= bit) return false;
	l = st;
	r = L - 1;
	
	while(l < r) {
		LL mid = (l + r) >> 1;
		if(A + mid * B < bit) l = mid + 1;
		else r = mid;
	}
	
	if(A + r * B >= bit) --r;
	l = st;
	st = r + 1; // 下一个起始位置 
	return true;
}

int main(){
	//freopen("MyOutput.txt","w",stdout);
	//freopen("input.txt","r",stdin);
	INIT();
	cin >> L >> A >> B >> mod;
	
	For(i, 1, 19) { // 枚举位数 
		if(getLR()) {
			Matrix mat(3, 3); 
			mat[0][0] = bit % mod;
			mat[0][1] = mat[0][2] = mat[1][2] = mat[2][1] = 0;
			mat[1][0] = mat[1][1] = mat[2][2] = 1;
			mat[2][1] = B % mod;
			
			mat = mat_pow_mod(mat, r - l + 1);
			
			Matrix ret(1, 3); 
			ret[0][0] = ans;
			ret[0][1] = (A + l * B) % mod;
			ret[0][2] = 1;
			
			ret *= mat;
			
			ans = ret[0][0];
		}
		bit *= 10;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256