#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;
ll MOD;

template<typename T, int N>
struct Matrix {
    using vec = vector<T>;
    using mat = vector<vec>;
    mat dat;

    constexpr Matrix() : dat(N, vec(N, 0)) {}
    Matrix(mat dat) : dat(dat) {}

    static constexpr Matrix identity() {
        Matrix e;
        for (int i = 0; i < N; ++i)  e.dat[i][i] = 1;
        return e;
    }

    vec& operator [](int i) { return dat[i]; }
    Matrix operator +(const Matrix & a) const { return add(a); }
    Matrix operator -(const Matrix & a) const { return sub(a); }
    Matrix operator *(const Matrix & a) const { return mul(a); }

    Matrix add(const Matrix & a) const {
        Matrix y;
        for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
            y.dat[i][j] = (dat[i][j] + a.dat[i][j]) % MOD;
        }
        return y;
    }
    Matrix sub(const Matrix & a) const {
        Matrix y;
        for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
            y.dat[i][j] = (dat[i][j] + MOD - a.dat[i][j]) % MOD;
        }
        return y;
    }
    Matrix mul(const Matrix & a) const {
        Matrix y;
        for (int i = 0; i < N; ++i) for (int k = 0; k < N; ++k) for (int j = 0; j < N; ++j) {
            y.dat[i][j] = (y.dat[i][j] + dat[i][k] * a.dat[k][j] % MOD) % MOD;
        }
        return y;
    }
    Matrix pow(ll n) const {
        Matrix x(dat), y = identity();
        while (n > 0) {
            if (n % 2) y = x.mul(y);
            x = x.mul(x);
            n >>= 1;
        }
        return y;
    }
};

ll L, A, B;

int main() {
    cin >> L >> A >> B >> MOD;
    const ll smax = A + B * (L - 1);

    ll ans = 0;
    ll pow10 = 10, mpow10 = 10 % MOD;
    ll lb = 0;
    Matrix<ll, 3> mat;
    rep(d, 0, 18) {
        ll ub;
        if (smax < pow10) ub = L;
        else if (A > pow10) ub = 0;
        else ub = (pow10 - A + B - 1) / B;
        ll cnt = ub - lb;
        //cerr << d + 1 << ": " << ub << " " << lb << " " << cnt << endl;

        if (cnt > 0) {
            mat[0][0] = mpow10, mat[0][1] = 1, mat[0][2] = 0;
            mat[1][0] = 0, mat[1][1] = 1, mat[1][2] = 1;
            mat[2][0] = 0, mat[2][1] = 0, mat[2][2] = 1;

            mat = mat.pow(cnt);
            ll first = (A + B * lb % MOD) % MOD;
            ans = ((ans * mat[0][0] % MOD + first * mat[0][1] % MOD) % MOD + B % MOD * mat[0][2] % MOD) % MOD;
        }
        pow10 *= 10;
        mpow10 = mpow10 * 10 % MOD;
        lb = ub;
    }
    write(ans);
}

Measured memory_bytes: 256