#include <bits/stdc++.h>
using namespace std;
using Int = long long;
Int powmod(Int x, unsigned long long y, Int M)
{
    if (y == 0) return 1;
    if (y % 2 == 0) return powmod(x*x%M, y/2, M);
    return x*powmod(x*x%M, y/2, M)%M;
}
Int f(Int A, Int B, Int R, Int N, Int M)
{
    if (N == 0) return 0;
    if (N % 2 == 0) return f((A*R+A+B)%M, 2*(B+R*B)%M, R*R%M, N/2, M);
    return (f(A, B, R, N-1, M)*R + (N-1)%M*B%M+A)%M;
}
int main()
{
    Int L, A, B, M; cin >> L >> A >> B >> M;
    array<Int, 19> counts = {};
    Int idx = 0;
    for (int i = 1; i < counts.size(); i++) {
        Int k = (Int)pow(10, i) - 1 - A;
        if (k < idx*B) continue;
        k /= B;
        k = min(L-1, k);
        counts[i] = k - idx + 1;
        idx += counts[i];
    }
    Int ans = 0;
    for (int i = 1; i < counts.size(); i++) {
        unsigned long long s = 0, t = 0;
        for (int j = 1; j < i; j++) s += counts[j];
        for (int j = i+1; j < counts.size(); j++) t += j * counts[j];
        ans = (ans + f((A%M+B%M*(s%M))%M, B%M, powmod(10, i, M), counts[i], M) * powmod(10, t, M)) % M;
    }
    cout << ans << '\n';
    return 0;
}
