#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using Matrix = vector<vector<ll>>;

inline ll ceil_ll(ll x, ll y) { return (x + y - 1) / y; }

Matrix mulMatrix(const Matrix &A, const Matrix &B, const ll MOD) {
    Matrix C(3, vector<ll>(3));
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                (C[i][j] += (A[i][k] * B[k][j]) % MOD) %= MOD;
            }
        }
    }
    return C;
}

Matrix powMatrix(Matrix A, ll e, const ll MOD) {
    vector<vector<ll>> X(3, vector<ll>(3));
    X[0][0] = X[1][1] = X[2][2] = 1;

    for ( ; 0 < e; e >>= 1) {
        if (e & 1) X = mulMatrix(X, A, MOD);
        A = mulMatrix(A, A, MOD);
    }
    return X;
}

using ull = unsigned long long;
ll fast_pow10(ull e, const ull MOD) {
    ull a = 10, x = 1;
    for ( ; 0 < e; e >>= 1) {
        if (e & 1) (x *= a) %= MOD;
        (a *= a) %= MOD;
    }
    return x;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    constexpr int DIGITS = 19;
    vector<ll> pow10(DIGITS);
    pow10[0] = 1;
    for (int i = 1; i < DIGITS; ++i)
        pow10[i] = 10 * pow10[i - 1];


    ll L, A, B, M;
    cin >> L >> A >> B >> M;

    vector<ll> begin(DIGITS), num(DIGITS);
    for (ll d = 1; d < DIGITS; ++d) {
        begin[d] = max(0ll, ceil_ll(pow10[d - 1] - A, B));
        const ll end = min((pow10[d] - A - 1) / B, L - 1);

        const ll s_l = A + B * begin[d], s_r = A + B * end;
        if (pow10[d - 1] <= s_l && s_r < pow10[d] && begin[d] <= end)
            num[d] = end - begin[d] + 1;
    }

    ll ans = 0;
    for (ll d = 1; d < DIGITS; ++d) {
        if (num[d] == 0) continue;

        Matrix X(3, vector<ll>(3));
        X[0][0] = pow10[d] % M; X[0][1] = 1;
        X[1][1] = 1; X[1][2] = B % M;
        X[2][2] = 1;

        X = powMatrix(X, num[d], M);

        const ll s0 = (A + B * begin[d]) % M;
        const ll s = ((X[0][1] * s0) % M + X[0][2]) % M;

        (ans *= fast_pow10((unsigned long long)d * num[d], M)) %= M;
        (ans += s) %= M;
    }

    cout << ans << endl;

    return 0;
}
