#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int64_t MOD;
int64_t MODN;

struct Matrix {
    vector<int64_t> buf;
    size_t _rsize;
    Matrix(size_t row, size_t col)
        : buf(row * col)
        , _rsize(row)
    {
    }

    size_t rsize() const
    {
        return _rsize;
    }
    size_t csize() const
    {
        return buf.size() / rsize();
    }
    Matrix pow(int64_t y)
    {
        if (y == 0) {
            Matrix m(rsize(), csize());
            for (size_t i = 0; i < rsize(); i++) {
                m(i, i) = 1;
            }
            return m;
        }
        if (y % 2 == 0) {
            return ((*this) * (*this)).pow(y / 2);
        } else {
            return (*this) * (this->pow(y - 1));
        }
    }
    int64_t& operator()(size_t i, size_t j)
    {
        return this->buf[j * rsize() + i];
    }
    const int64_t& operator()(size_t i, size_t j) const
    {
        return this->buf[j * rsize() + i];
    }

    friend Matrix operator*(const Matrix& lh, const Matrix& rh)
    {
        if (lh.csize() != rh.rsize()) {
            throw runtime_error("the number of columns of 1st argument and the number of rows of 2nd argument does not match!");
        }

        Matrix result(lh.rsize(), rh.csize());
        for (size_t i = 0; i < result.rsize(); i++) {
            for (size_t j = 0; j < result.csize(); j++) {
                result(i, j) = 0;
                for (size_t k = 0; k < lh.csize(); k++) {
                    result(i, j) += lh(i, k) * rh(k, j) % MOD;
                    result(i, j) %= MOD;
                }
            }
        }
        return result;
    }
};

int64_t dpow(const int64_t x, const int64_t y)
{
    if (y == 0) {
        return 1;
    }
    if (y % 2 == 0) {
        return dpow(x * x % MOD, y / 2);
    } else {
        return x * dpow(x, y - 1) % MOD;
    }
}

int64_t inv(int64_t x)
{
    return dpow(x, MODN - 1);
}

int64_t dfloor(int64_t x, int64_t y);
int64_t dceil(int64_t x, int64_t y);

int64_t dfloor(int64_t x, int64_t y)
{
    if (y < 0) {
        return dfloor(-x, -y);
    }
    if (x < 0) {
        return -dceil(-x, y);
    }
    return x / y;
}

int64_t dceil(int64_t x, int64_t y)
{
    if (y < 0) {
        return dceil(-x, -y);
    }
    if (x < 0) {
        return -dfloor(-x, y);
    }
    return (x + y - 1) / y;
}

vector<pair<int64_t, int>> primes;

int main()
{
    int64_t L, A, B;
    cin >> L >> A >> B >> MOD;

    int64_t tmp = MOD;
    for (int64_t i = 2; i * i <= tmp; i++) {
        bool isPrime = true;
        for (int64_t j = 2; j * j <= i; j++) {
            isPrime = isPrime && i % j != 0;
        }
        if (isPrime) {
            int cnt = 0;
            while (tmp % i == 0) {
                tmp /= i;
                cnt++;
            }
            if (cnt > 0) {

                primes.push_back(make_pair(i, cnt));
            }
        }
    }
    if (tmp != 1) {
        primes.push_back(make_pair(tmp, 1));
    }
    MODN = 1;
    for (const auto& pa : primes) {
        int64_t p;
        int n;
        tie(p, n) = pa;
        MODN *= p - 1;
        rep(i, n - 1)
        {
            MODN *= p;
        }
    }

    int64_t result = 0;
    rep(d, 18)
    {
        int64_t e = 1;
        rep(i, d)
        {
            e *= 10;
        }
        int64_t lb = max(0L, dceil(e - A, B));
        int64_t ub = min(L - 1, dfloor(10 * e - A - 1, B));
        int64_t m = ub - lb;

        if (m >= 0) {
            Matrix E(1, 1);
            E(0, 0) = 10L;
            Matrix co(3, 3);
            co(0, 0) = E.pow(d + 1)(0, 0);
            co(0, 1) = 1;
            co(1, 1) = 1;
            co(1, 2) = B % MOD;
            co(2, 2) = 1;

            Matrix p = co.pow(m + 1);
            int64_t si = (A % MOD + lb % MOD * (B % MOD) % MOD) % MOD;
            int64_t T = (p(0, 1) * si % MOD + p(0, 2)) % MOD;

            Matrix sh(1, 1);
            sh(0, 0) = E.pow(d + 1)(0, 0);
            result = (result * sh.pow(m + 1)(0, 0) % MOD + T) % MOD;
        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256