// May this submission get accepted
#include <bits/stdc++.h>

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using namespace std;

// AtCoder/Codeforces 用 デバッグ検知
#ifdef ONLINE_JUDGE
constexpr bool DEBUG_MODE = false;
#else
constexpr bool DEBUG_MODE = true;
#endif

// エイリアス (補完・コンパイルが重くなる)
// #include <boost/multiprecision/cpp_int.hpp>
// using mll = boost::multiprecision::cpp_int;

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define FOREACH(i,q) for (auto &i : q)
template<class T> bool chmax(T &a, const T b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T b) { if (a > b) {a = b; return true;} return false; }
constexpr int INF = numeric_limits<int>::max();
constexpr long long LINF = numeric_limits<long long>::max();
constexpr long double EPS = 1e-10L;
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define IIF(q,t,f) ((q) ? (t) : (f))
#define DUMP(q) DUMP_FUNC(q, #q, __FILE__, __LINE__)
template <typename T> void DUMP_PROC(T x) { if (is_integral<T>() || is_floating_point<T>()) cerr << "\e[32m" << x << "\e[m"; else cerr << x; }
template<> void DUMP_PROC<char>(char x) { cerr << "\e[36m\'" << x << "\'\e[m"; }
template<> void DUMP_PROC<string>(string x) { cerr << "\e[33m\"" << x << "\"\e[m"; }
template <typename T, typename U> void DUMP_PROC(pair<T, U> x) { cerr << "{"; DUMP_PROC(x.first); cerr << ", "; DUMP_PROC(x.second); cerr << "}"; }
template <typename ...T, typename U, U... Seq> void DUMP_PROC(tuple<T...> &x, integer_sequence<U, Seq...>) { (void)(int[]){(cerr << ((const char*[]){"", ", "})[!!Seq] << (DUMP_PROC(get<Seq>(x)), ""), 0)...}; }
template <typename ...T> void DUMP_PROC(tuple<T...> x) {cerr << "{"; DUMP_PROC(x, index_sequence_for<T...>()); cerr << "}";}
template <typename T> void DUMP_PROC(vector<T> x) { cerr << "["; for (auto &xi : x) { DUMP_PROC(xi); cerr << (&xi != &*x.rbegin()?", ":""); } cerr << "]"; }
template <typename T> void DUMP_FUNC(T x, const char* name, const char* fn, int ln) { cerr << "\e[32m[DEBUG]\e[m " << name << ": "; DUMP_PROC(x); cerr << " @ " << fn << "(" << ln << ")" << endl; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// 標準入出力
struct qin { // query input
    size_t sz;
    qin(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
qin in1; // input one
template <typename T> void say(const T x, const char* end = "\n") { cout << x << end; }
void say(const ld x, const char* end = "\n") { cout << setprecision(30) << x << end; }
template <typename T> void say(const vector<T> x, const char* sep = " ", const char* end = "\n") { REP(i, x.size()) { cout << x[i] << (i+1 == i_len ? end : sep); } }
template <typename T> void say(const vector<vector<T>> x, const char* sep = " ", const char* end = "\n") { REP(i, x.size()) { say(x[i], sep, end); } }

// モジュール
// [[LIBRARY]] modint_petit.cpp linalg2.cpp
// [Inclusion] linalg2.cpp
// 行列演算
// pdivの余りを取りたくない場合はoperator+=/-=/*のコメントアウトを適宜
ll pdiv = 1000000007LL;

template <typename T = ll>
class matrix {
private:
    size_t col_size, row_size;
    vector<T> raw;
public:
    matrix() : col_size(0), row_size(0), raw() {}
    matrix(size_t n) : col_size(1), row_size(n), raw(n, 0) {}
    matrix(size_t n, size_t m) : col_size(m), row_size(n), raw(n * m, 0) {}
    matrix(const vector<vector<T>> &a) : col_size(a.size() ? a[0].size() : 0), row_size(a.size()), raw(col_size * row_size) {
        for (size_t i = 0; i < row_size; i++) {
            for (size_t j = 0; j < col_size; j++) {
                at(i, j) = a[i][j];
            }
        }
    }
    matrix(initializer_list<T> init) : col_size(init.size()), row_size(1), raw(init) {}
    matrix(initializer_list<initializer_list<T>> init) : col_size(0), row_size(0), raw() {
        const size_t n = init.size();
        const size_t m = [&]() {
            size_t maxm = 0;
            for (const auto& initi : init) {
                const size_t mi = initi.size();
                if (mi > maxm) maxm = mi;
            }
            return maxm;
        }();
        tie(row_size, col_size) = make_pair(n, m);
        raw.resize(n * m);
        size_t i = 0, j = 0;
        for (const auto &initi : init) {
            for (const auto &v : initi) {
                at(i, j++) = v;
            }
            i++; j = 0;
        }
    }
    size_t rows() const { return row_size; }
    size_t cols() const { return col_size; }
    const T& at(const size_t i, const size_t j) const { return raw.at(i * col_size + j); }
    const T& at(const size_t i) const { return raw.at(i); }
    T& at(const size_t i, const size_t j) { return raw.at(i * col_size + j); }
    T& at(const size_t i) { return raw.at(i); }
    T& operator() (size_t i, size_t j) { return raw[i * col_size + j]; }
    T& operator() (size_t i) { return raw[i]; }
    T& operator[] (size_t i) { return raw[i]; }
    const T& operator() (size_t i, size_t j) const { return raw[i * col_size + j]; }
    const T& operator() (size_t i) const { return raw[i]; }
    const T& operator[] (size_t i) const { return raw[i]; }
    matrix<T>& operator+= (const matrix<T> &a) {
        for (size_t i = 0; i < row_size; i++) {
            for (size_t j = 0; j < col_size; j++) {
                // at(i, j) += a.at(i, j);
                if ((at(i, j) += a.at(i, j)) >= pdiv) at(i, j) -= pdiv;
            }
        }
        return *this;
    }
    matrix<T>& operator-= (const matrix<T> &a) {
        for (size_t i = 0; i < row_size; i++) {
            for (size_t j = 0; j < col_size; j++) {
                // at(i, j) -= a.at(i, j);
                if ((at(i, j) +=  pdiv - a.at(i, j)) >= pdiv) at(i, j) -= pdiv;
            }
        }
        return *this;
    }
    matrix<T> operator* (const matrix<T> &a) {
        assert(col_size == a.row_size);
        const size_t n = row_size, m = col_size, q = a.col_size;
        matrix<T> r(n, q);
        for (size_t i = 0; i < n; i++) {
            for (size_t k = 0; k < m; k++) {
                for (size_t j = 0; j < q; j++) {
                    // r.at(i, j) += at(i, k) * a.at(k, j);
                    (r.at(i, j) += at(i, k) * a.at(k, j) % pdiv) %= pdiv;
                }
            }
        }
        return r;
    }
    
    matrix<T> operator+ (const matrix<T> &a) const {
        matrix<T> r = *this;
        return r += a;
    }
    matrix<T> operator- (const matrix<T> &a) const {
        matrix<T> r = *this;
        return r -= a;
    }
    matrix<T>& operator*= (const matrix<T> &a) {
        return *this = move(*this * a);
    }
    operator T () const {
        assert(col_size == 1 && row_size == 1);
        return raw[0];
    }
    static matrix<T> eye(size_t n) {
        matrix<T> r(n, n);
        for (size_t i = 0; i < n; i++)
            r.at(i, i) = 1;
        return r;
    }
    matrix<T> transpose() const {
        matrix<T> r(col_size, row_size);
        for (size_t i = 0; i < col_size; i++) {
            for (size_t j = 0; j < row_size; j++) {
                r.at(i, j) = at(j, i);
            }
        }
        return r;
    }
    matrix<T> pow(long long int n) const {
        assert(row_size == col_size);
        matrix<T> r = eye(row_size);
        matrix<T> a = *this;
        while (n) {
            if (n & 1) r *= a;
            n /= 2;
            if (n) a *= a;
        }
        return r;
    }
};
template <typename T>
void DUMPMTR(matrix<T> m) {
    cerr << "[DEBUG] DUMPMTR: " << endl;
    for (size_t i = 0; i < m.rows(); i++) {
        cerr << " ["[!i] << "[";
        for (size_t j = 0; j < m.cols(); j++) {
            cerr << setw(4) << m(i, j) << " ]"[j+1 == m.cols()];
        }
        if (i+1 == m.rows()) cerr << ']';
        cerr << endl;
    }
}

// [Inclusion] modint_petit.cpp
// 剰余演算ライブラリ (小): 剰余と逆元だけ欲しいときに使う軽量ライブラリ
// mod pdiv 上での a^n
ll modpow(const ll a, ll n, const ll pdiv) {
    if (a == 0) return 0;
    ll r = 1;
    ((n %= pdiv-1) += pdiv-1) %= pdiv-1; // a^(p-1) === a^0 mod pdiv
    for (ll b = (a % pdiv + pdiv) % pdiv; n; n >>= 1, (b *= b) %= pdiv) if (n & 1) (r *= b) %= pdiv;
    return r;
}
inline ll modinv(const ll a, const ll pdiv) { return modpow(a, pdiv-2, pdiv); }

// [[/LIBRARY]]

// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll l, a, b, m;
    cin >> l >> a >> b >> m;
    pdiv = m;

    constexpr ll dmax = 19;
    vector<ll> dsup(dmax);
    REP(i, dmax) {
        ll ok = -1;
        ll ng = l;
        while (ng - ok > 1) {
            ll md = (ok + ng + 1) / 2;
            ll sz = to_string(a + b * md).size();
            (sz <= i ? ok : ng) = md;
        }
        dsup[i] = ng;
    }

    // DUMP(dsup);
    
    ll left = 0;
    auto w = matrix<ll>::eye(3);
    REP(i, dmax) {
        ll right = dsup[i];
        if (left < right) {
            matrix<ll> wi = {
                {modpow(10, i, m), 1, 0},
                {0, 1, b % m},
                {0, 0, 1}
            };
            w *= wi.pow(right - left).transpose();
        }
        left = right;
    }
    auto x0 = matrix<ll>({0, a % m, 1});
    x0 *= w;
    say(x0[0]);
    
}

Measured memory_bytes: 256