#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

class ModInt {
    using u64 = std::uint_fast64_t;
    static u64 &mod() {
        static u64 mod_ = 0;
        return mod_;
    }

   public:
    u64 x;
    ModInt(const ll x = 0) : x(x < 0 ? (mod() - (-x % mod())) % mod() : x % mod()) {}

    ModInt operator+(const ModInt r) { return ModInt(*this) += r; }
    ModInt operator*(const ModInt r) { return ModInt(*this) *= r; }
    ModInt operator-(const ModInt r) { return ModInt(*this) -= r; }
    ModInt operator/(const ModInt r) { return ModInt(*this) /= r; }
    ModInt operator-() { return ModInt(mod() - x); }

    ModInt &operator+=(const ModInt r) {
        x += r.x;
        if (x >= mod()) x -= mod();
        return *this;
    }
    ModInt &operator-=(const ModInt r) {
        if (x < r.x) x += mod();
        x -= r.x;
        return *this;
    }
    ModInt &operator*=(const ModInt r) {
        x *= r.x;
        if (x >= mod()) x %= mod();
        return *this;
    }
    ModInt &operator/=(ModInt r) {
        if (!(x % r.x)) {
            x /= r.x;
            return *this;
        }
        u64 p = mod() - 2;
        while (p > 0) {
            if (p & 1) *this *= r;
            r *= r;
            p >>= 1;
        }
        return *this;
    }
    ModInt &operator++(int) { return (*this) += 1; }
    ModInt &operator++() { return (*this) += 1; }
    ModInt &operator--(int) { return (*this) -= 1; }
    ModInt &operator--() { return (*this) -= 1; }

    bool operator<(const ModInt r) { return x < r.x; }
    bool operator>(const ModInt r) { return x > r.x; }
    bool operator<=(const ModInt r) { return x <= r.x; }
    bool operator>=(const ModInt r) { return x >= r.x; }
    bool operator==(const ModInt r) { return x == r.x; }
    bool operator!=(const ModInt r) { return x != r.x; }

    ModInt inv() { return (ModInt)1 / (*this); }
    int get_mod() { return mod(); }

    friend std::istream &operator>>(std::istream &in, ModInt &m) {
        ll a;
        in >> a;
        if (a < 0) a = mod() - (-a % mod());
        if (a >= mod()) a %= mod();
        m.x = a;
        return in;
    }
    friend std::ostream &operator<<(std::ostream &out, const ModInt &m) {
        out << m.x;
        return out;
    }

    static void set_mod(const u64 m) { mod() = m; }
};
using mint = ModInt;

template <typename T>
class Matrix {
   public:
    vector<vector<T>> mat;
    const size_t height, width;
    Matrix(size_t height, size_t width, T e = 0) : height(height), width(width) {
        mat.assign(height, vector<T>(width, e));
    }
    Matrix(vector<vector<T>> m) : mat(m), height(m.size()), width(m[0].size()) {}

    Matrix operator+(const Matrix r) { return Matrix(*this) += r; }
    Matrix operator*(const Matrix r) { return Matrix(*this) *= r; }
    Matrix operator-(const Matrix r) { return Matrix(*this) -= r; }
    Matrix operator*(const T x) { return Matrix(*this) *= x; }
    Matrix operator-() { return Matrix(*this) *= -1; }

    Matrix &operator+=(const Matrix a) {
        assert(height == a.height && width == a.width);
        for (int i = 0; i < height; i++)
            for (int j = 0; j < width; j++) mat[i][j] += a[i][j];

        return *this;
    }
    Matrix &operator-=(const Matrix a) {
        assert(height == a.height && width == a.width);
        for (int i = 0; i < height; i++)
            for (int j = 0; j < width; j++) mat[i][j] -= a[i][j];

        return *this;
    }
    Matrix &operator*=(const Matrix a) {
        assert(width == a.height);
        vector<vector<T>> b(height, vector<T>(a.width, 0));
        for (int i = 0; i < height; i++)
            for (int j = 0; j < a.width; j++)
                for (int k = 0; k < width; k++) b[i][j] += mat[i][k] * a[k][j];
        mat.swap(b);
        return *this;
    }
    Matrix &operator*=(const T x) {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                mat[i][j] *= x;
            }
        }
    }

    T det() {
        assert(height == width);
        Matrix b(*this);
        T res = 1;
        for (int i = 0; i < width; i++) {
            int idx = -1;
            for (int j = i; j < width; j++) {
                if (b[i][j] != 0) idx = j;
            }
            if (idx == -1) return 0;
            if (i != idx) {
                res *= -1;
                swap(b[i], b[idx]);
            }
            res *= b[i][i];
            T x = b[i][i];
            for (int j = 0; j < width; j++) {
                b[i][j] /= x;
            }
            for (int j = i + 1; j < width; j++) {
                T a = b[j][i];
                for (int k = 0; k < width; k++) {
                    b[i][k] -= b[i][k] * a;
                }
            }
        }
        return res;
    }

    vector<T> &operator[](int i) { return mat[i]; }
    const vector<T> &operator[](int i) const { return mat[i]; }
    friend std::ostream &operator<<(std::ostream &out, const Matrix &a) {
        for (int i = 0; i < a.height; i++) {
            out << "( ";
            for (int j = 0; j < a.width; j++) out << a[i][j] << (j + 1 == a.width ? " )\n" : ",");
        }
        return out;
    }
    static Matrix<T> I(size_t n) {
        Matrix<T> I(n, n);
        for (int i = 0; i < n; i++) I[i][i] = 1;
        return I;
    }
};

template <typename T, typename U>
T pow(T x, U n, T e = 1) {
    T res = e;
    while (n > 0) {
        if (n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

// A + kB <= Y <=> k <= (Y-A)/B
int main() {
    ll L, A, B, M;
    cin >> L >> A >> B >> M;
    mint::set_mod(M);
    vector<ll> C(19);
    for (int i = 1; i <= 18; i++) {
        ll l, r;
        ll i10 = ::pow<ll, int>(10, i);
        l = (i10 / 10 - A - 1) < 0 ? -1 : (i10 / 10 - A - 1) / B;
        r = (i10 - A - 1) < 0 ? -1 : (i10 - A - 1) / B;
        l = min(l, L - 1), r = min(r, L - 1);
        C[i] = r - l;
    }
    mint X = 0;
    mint S = A;
    for (int i = 1; i < 19; i++) {
        Matrix<mint> U({{::pow<ll, int>(10, i), 1, 0}, {0, 1, B}, {0, 0, 1}});
        Matrix<mint> V({{X}, {S}, {1}});
        V.mat = (pow<Matrix<mint>, ll>(U, C[i], Matrix<mint>::I(3)) * V).mat;
        X = V[0][0];
        S = V[1][0];
    }
    cout << X << endl;
    return 0;
}

Measured memory_bytes: 256