#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

ll L, A, B, M;

vector<vector<ll>>& operator*=(vector<vector<ll>>& lhs, vector<vector<ll>> rhs) {
    auto result = lhs;
    for (ll i = 0; i < result.size(); i++) {
        for (ll j = 0; j < result[i].size(); j++) {
            result[i][j] = 0;
            for (ll k = 0; k < lhs.size(); k++) {
                (result[i][j] += lhs[i][k] * rhs[k][j] % M) %= M;
            }
        }
    }
    return lhs = result;
}

int main() {
    cin >> L >> A >> B >> M;

    ll ans = 0;
    ll pre = 0;
    ll s = A;
    for (ll d = 1; d <= 18; d++) {
        ll target = 1;
        for (ll j = 0; j < d; j++) {
            target *= 10;
        }
        ll low = pre - 1, eq_high = L;
        while (low != eq_high - 1) {
            ll mid = (low + eq_high) / 2;
            ll s_mid = A + B * mid;
            (s_mid < target ? low = mid : eq_high = mid);
        }

        ll C_d = eq_high - pre;
        pre = eq_high;

        vector<vector<ll>> mat = {
                { target % M,     0, 0 },
                {          1,     1, 0 },
                {          0, B % M, 1 }
        };

        vector<vector<ll>> result = {
                { 1, 0, 0 },
                { 0, 1, 0 },
                { 0, 0, 1 }
        };

        while (C_d) {
            if (C_d % 2 == 1) {
                result *= mat;
            }

            C_d /= 2;
            mat *= mat;
        }

        vector<ll> v = { ans, s, 1 };
        ans = 0;
        s = 0;
        for (ll i = 0; i < 3; i++) {
            (ans += v[i] * result[i][0] % M) %= M;
            (s += v[i] * result[i][1] % M) %= M;
        }
    }

    cout << ans << endl;
}