#include <bits/stdc++.h>
#define ll long long
using namespace std;

inline ll read() {
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
	return x * f;
}

ll mod;

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

M qp(M a, ll b) {
	M c;
	for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) c.a[i][j] = i == j;
	while (b) {
		if (b & 1) c = c * a;
		a = a * a;
		b >>= 1;
	}
	return c;
}

int main() {
	ll n = read(), a0 = read(), d = read(); mod = read();
	n--;
	ll bit = 10, ans = 0;
	ll st = 0;
	for (int i = 1; i <= 19; i++) {
		ll l = st, r = n, p = -1;
		while (l <= r) {
			ll mid = l + r >> 1;
			if (mid * d + a0 < bit) l = mid + 1, p = mid;
			else r = mid - 1;
		}
		if (p != -1) {
			M a;
			a.a[0][0] = bit % mod; a.a[0][1] = a.a[1][1] = a.a[2][2] = 1LL;
			a.a[0][2] = a.a[1][0] = a.a[2][0] = a.a[2][1] = 0LL;
			a.a[1][2] = d % mod;
			a = qp(a, p - st + 1);
			ll ast = a0 % mod + d % mod * st % mod; ast %= mod; 
			ans = (ans * a.a[0][0] % mod + ast * a.a[0][1] % mod + a.a[0][2] % mod) % mod;
			st = p + 1;
		}
		if (st > n) break;
		bit *= 10;
	}
	printf("%lld\n", ans);
	return 0;
}