#include<bits/stdc++.h>
#define lowbit(a) ((a)&(-(a)))
using namespace std;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	}
}

long long L, A, B;
long long mod;
long long ans = 0;
long long powt[19];
struct mat {
	int val[3][3];
	mat() { memset(val, 0, sizeof val); }
	void init(int i)
	{
		memset(val, 0, sizeof val);
		val[0][0] = powt[i] % mod, val[1][0] = val[1][1]= val[2][2] = 1;
		val[2][1]=B%mod;
	}
}a,res;

mat operator*(mat a, mat b)
{
	mat c;
	for (int i = 0; i<3; i++)
		for (int j = 0; j<3; j++)
			for (int k = 0; k<3; k++)
				c.val[i][j] = (c.val[i][j] + 1ll * a.val[i][k] * b.val[k][j]) % mod;
	return c;
}

void poww(long long L,long long R,int d)
{
	long long n = (R - L) / B + 1;
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			res.val[i][j] = (i == j);

	a.init(d);

	while (n)
	{
		if (n & 1)res = res * a;
		n >>= 1;
		a = a*a;
	}
	ans = (1ll * ans*res.val[0][0]%mod + L % mod*res.val[1][0] % mod + res.val[2][0]) % mod;
}

int main()
{
	cin >> L >> A >> B >> mod;
	powt[0] = 1;
	for (int i = 1; i <= 18; i++)
		powt[i] = powt[i - 1] * 10ll;

	long long ed = A + B * (L - 1);

	for (int d = 1; d <= 18; d++)
	{
		if (A < powt[d])
		{
			long long R = (powt[d] - 1 - A) / B * B + A;
			R = min(R, ed);
			poww(A, R, d);
			if (R == ed)break;
			A = R + B;
		}
	}
	cout << ans << endl;
	return 0;
}