// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = uint64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

ll L, A, B, M;
ll mod;
using Mat = VV<ll>;

Mat make_mat(ll r, ll c) { return move(make_v<ll>(0, r, c)); }
Mat make_id(ll r, ll c) {
    auto ret = make_v<ll>(0, r, c);
    for(ll i = 0; i < min(r, c); i++) ret[i][i] = 1;
    return move(ret);
}
Mat make_id(const Mat &a) { return move(make_id(a.size(), a[0].size())); }

Mat operator*(const Mat &a, const Mat &b) {
    Mat ret = make_mat(a.size(), b[0].size());
    for(ll i = 0; i < ret.size(); i++) {
        for(ll j = 0; j < ret[0].size(); j++) {
            ll tmp = 0;
            for(ll k = 0; k < a[0].size(); k++) (tmp += a[i][k] % mod * b[k][j] % mod) %= mod;
            ret[i][j] = tmp;
        }
    }
    return move(ret);
}

Mat pow__(Mat a, ll b) { return b ? (b & 1 ? a : make_id(a)) * pow__(a * a, b / 2) : make_id(a); }
ll pow__(ll a, ll b) { return b ? (b & 1 ? a : 1) * pow__(a * a % mod, b / 2) % mod : 1; }

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

    auto now_mat = make_id(3, 3);

    ll last_idx = 0;
    for(ll dig = 1; dig <= 18 && last_idx < L; dig++) {
        ll lower = 1;
        for(ll i = 1; i < dig; i++) lower *= 10;
        ll upper = lower * 10;
        
        if(upper < A) continue;

        ll lower_idx = last_idx;
        ll upper_idx = (upper - A) / B + !!((upper - A) % B);
        chmin(upper_idx, L);
        DEBUG(PLL(lower, upper));
        DEBUG(PLL(lower_idx, upper_idx));
        if(upper_idx == lower_idx) continue;

        auto mat = Mat {
            { lower % mod * 10 % mod, 1, 0, },
            { 0, 1, 1, },
            { 0, 0, 1, },
        };

        now_mat = pow__(mat, upper_idx - lower_idx) * now_mat;
        last_idx = upper_idx;
    }

    Mat vec = {
        { 0 },
        { A % mod },
        { B % mod },
    };

    auto ans_v = now_mat * vec;
    ll ans = ans_v[0][0];

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256