#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

class mod_int {
    using ll = long long;

public:
    static int Mod;
    static constexpr mod_int e() {
        return mod_int{1}; 
    }

    constexpr mod_int() : n(0) {}
    constexpr mod_int(int n_) : n(n_) {
        if(n >= Mod)     n %= Mod;
        else if(n < 0) n = (n % Mod + Mod) % Mod;
    }
    constexpr mod_int(ll n_) : n(n_) { n = (n + Mod) % Mod; }

    constexpr operator int() const { return n; }
    constexpr operator ll() const  { return n; }

    constexpr bool operator==(mod_int const& other) const { return n == other.n; }
    mod_int& operator+=(mod_int const& other) {
        if((n += other.n) >= Mod) n -= Mod;
        return *this;
    }
    mod_int& operator-=(mod_int const& other) {
        if((n += Mod - other.n) >= Mod) n -= Mod;
        return *this;
    }
    mod_int& operator*=(mod_int const& other) {
        n = (unsigned long long)n * other.n % Mod;
        return *this;
    }

    mod_int operator+(mod_int other) const { return mod_int(*this) += other; }
    mod_int operator-(mod_int other) const { return mod_int(*this) -= other; }
    mod_int operator*(mod_int other) const { return mod_int(*this) *= other; }

    friend std::istream& operator>>(std::istream& is, mod_int& n) {
      is >> n.n;
      return is;  
    }

    friend std::ostream& operator<<(std::ostream& os, mod_int const& n) {
        os << n.n;
        return os;
    }

private:
    ll n;
};

int mod_int::Mod = 1;

template<typename T, size_t H, size_t W>
class Matrix {
private:
    std::array<std::array<T, W>, H> mat;
public:
    using value_type = T;
    static constexpr int rows = H;
    static constexpr int cols = W;
    static Matrix e() {
        Matrix e;
        for(int i=0; i<rows; i++) e.mat[i][i] = T{1};

        return e;
    }

    Matrix() : mat{} {}
    Matrix(Matrix&&) = default; // move
    Matrix& operator=(Matrix&&) = default;
    Matrix(const Matrix&) = default; // copy
    Matrix& operator=(const Matrix&) = default;
    ~Matrix() = default;

    // restrict constructor from initializer_list
    template<typename U>
    Matrix(std::initializer_list<U>) = delete;

    template<typename U>
    Matrix& operator= (std::initializer_list<U>) = delete;

    // construct from nested initializer_list(to fix)
    Matrix(std::initializer_list<std::initializer_list<T>> m) {
        int i = 0, j = 0;
        for(const auto& v : m){
            for(T e : v){
                assert(i < rows && j < cols);
                mat[i][j] = e;
                j++;
            }   
            i++;
            j = 0;
        }
    }

    // accessor
    T& operator() (int i, int j) {
        return mat[i][j];
    }

    const T& operator() (int i, int j) const {
        return mat[i][j];
    }

    // utility
    template<typename F>
    Matrix& apply(F f){
        for(const auto& row : mat)for(T e : row) {
            f(e);
        }

        return *this;
    }

    void dump() {
        std::cout << "==========================" << std::endl;
        std::cout << mat.size() << " " << mat[0].size() << std::endl;
        for(const auto& row : mat) {
            for(T e : row) {
                std::cout << e << " ";
            }
            std::cout << std::endl;
        }
        std::cout << "==========================" << std::endl;
    }

    // Matrix and scalar
    Matrix& operator+= (const T& v) { 
        apply([&](T& x) { x += v; });
        return *this;
    }
    Matrix& operator*= (const T& v) {
        apply([&](T& x) { x *= v; });
        return *this;
    }

    friend Matrix operator+ (const Matrix& m, const T& v) {
        auto ret = m;
        ret += v;
        return ret;
    }

    friend Matrix operator+ (const T& v, const Matrix& m) {
        return m + v;
    }

    friend Matrix operator* (const Matrix& m, const T& v) {
        auto ret = m;
        ret *= v;
        return ret;
    }

    friend Matrix operator* (const T& v, const Matrix& m) {
        return m * v;
    }
    
    // Matrix and Matrix
    friend Matrix operator+ (const Matrix& m1, const Matrix& m2) {
        for(int i=0; i<rows; i++)for(int j=0; j<cols; j++){
            m1(i, j) += m2(i, j);
        }
    }
    
    template<typename Other>
    friend Matrix<value_type, rows, Other::cols> operator* (const Matrix& m1, const Other& m2) {
        Matrix<T, rows, Other::cols> ret;
        for(int i=0; i<rows; i++)for(int j=0; j<Other::cols; j++)for(int k=0; k<cols; k++){
            ret(i, j) += m1(i, k) * m2(k, j);
        }

        return ret;
    }

    template<typename Other>
    friend Matrix<value_type, Other::rows, cols> operator* (const Matrix& m1, const Matrix& m2) {
        return m2 * m1;
    }
};

template<typename T>
T pow(T x, ll n) {
    if(n == 0) 
        return T::e(); 
    else
        return pow(x * x, n / 2) * (n % 2 ? x : T::e());
}

template<>
ll pow(ll x, ll n) {
    if(n == 0)
        return 1LL;
    else 
        return pow(x * x, n / 2) * (n % 2 ? x : 1LL);
}

int main() {
    using mint = mod_int;
    ll l, a, b, m; cin >> l >> a >> b >> m;
    mint::Mod = m;
    
    // [0, x]
    auto f = [&](ll x) {
        if(x < a) return 0LL;
        return min((x - a) / b, l - 1) + 1;
    };

    mint x{0}, s{a};

    for(ll d=1; d<=18; d++){
        Matrix<mint, 1, 3> v{{x, s, 1}};
        Matrix<mint, 3, 3> m{
            {pow(mint{10}, d), 0, 0},
            {1, 1, 0},
            {0, b, 1}
        };
        
        // d-digit
        v = v * pow(m, f(pow(10LL, d) - 1) - f(pow(10LL, d-1) - 1));

        x = v(0, 0); s = v(0, 1);
    }

    cout << x << endl;

    return 0;
}


Measured memory_bytes: 256