// ooooo      ooo                     
// `888b.     `8'                     
//  8 `88b.    8   .ooooo.   .oooo.   
//  8   `88b.  8  d88' `88b `P  )88b  
//  8     `88b.8  888   888  .oP"888  
//  8       `888  888   888 d8(  888  
// o8o        `8  `Y8bod8P' `Y888""8o 
// C++ Conpetitive Programming Template 
// Ver 2.4 (codename: Noa)
// Last Modified : 2019-06-10
// Created       : 2019-05-25
// Auther        : shirataki3
#include <bits/stdc++.h>
using namespace std;
// typename alias
template <class T> using vec = vector<T>;
template <class T> using vvec = vec<vec<T> >;
template <class T, class U> using vep = vec<pair<T,U> >;
template <class T> using PQ = priority_queue<T>;
using ll = long long;
using vll = vec<ll>;
using pll = pair<ll, ll>;
using vpll = vec<pll>;
using str = string;
// きけん
//#define int ll
#define bits(x) (1LL << (n))

// const
static const long long INF = 1LL<<59;
static const int iINF = 1LL<<30;
static const double dINF = 1e290;
static const long long MOD = (ll)1e9+7;
static const double PI = 3.14159265358979323846;

// accelerate stdin, stdout
#define endl "\n"
#define presolve(n) ios_base::sync_with_stdio(false);cin.tie(NULL);cout.setf(ios::fixed);cout.precision(n);
// repeat macro
#define __ov3(_1, _2, _3, name, ...) name
#define REP(i, n) for(ll (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(ll (i)=(a);(i)<=(b);i++)
#define rFOR(i, a, b) for(ll (i)=(b);(i)>=(a);i--)
#define rep(...) __ov3(__VA_ARGS__, FOR, REP,)(__VA_ARGS__)
// vector macro
#define rng(v) (v).begin(), (v).end()
#define ASC(v) sort(rng(v))
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse(rng(v))
#define FOLDL(src, dst, lambda) partial_sum(rng(src), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum(rng(src), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate(rng(v), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())
template <typename T> T min(vec<T> v) {return *min_element(rng(v));}
template <typename T> T max(vec<T> v) {return *max_element(rng(v));}

template <typename T> inline bool chmin(T& a, const T& b) {if(a > b) {a = b;return 1;}return 0;}  
template <typename T> inline bool chmax(T& a, const T& b) {if(a < b) {a = b;return 1;}return 0;}


// io helper
template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}
template <typename T>istream& operator>>(istream &is, vec<T> &v) {for(auto &a:v) is >> a; return is;}
template <typename T>ostream& operator<<(ostream &os, vec<T> &v) {os << "[";REP(i, v.size() - 1) os << v[i] <<", "; os << v[v.size()-1]<<"]";return os;}
template <typename T, typename U>ostream& operator<<(ostream &os, pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")";return os;}
template <size_t N, typename T>ostream& operator<<(ostream &os, array<T, N> &v) {os << "[";REP(i, N - 1) os << v[i] <<", "; os << v[N-1]<<"]";return os;}
template <typename T, typename U>ostream& operator<<(ostream &os, map<T, U> &mp) {os << "{ ";for(auto &p:mp) os << p.first << ": " << p.second << ", "; os << "}";return os;}

// 剰余を考慮した整数
ll Mod;
class mint {
    using u64 = uint64_t;
    public:
    u64 a;
    mint() : a(0) {}
    mint(const u64 x) : a(x % Mod){}
    void set(const u64 x = 0) { a = x % Mod; }
    static ll add_identity() {return mint(0);}
    static ll mul_identity() {return mint(1);}
    u64 &value() noexcept { return a; }
    const u64 &value() const noexcept { return a; }
    mint operator+(const mint rhs) const noexcept {return mint(*this) += rhs;}
    mint operator-(const mint rhs) const noexcept {return mint(*this) -= rhs;}
    mint operator*(const mint rhs) const noexcept {return mint(*this) *= rhs;}
    mint operator/(const mint rhs) const noexcept {return mint(*this) /= rhs;}
    mint &operator+=(const mint rhs) noexcept {a += rhs.a;if (a >= Mod) a -= Mod;return *this;}
    mint &operator++() noexcept {a += 1;if (a >= Mod) a -= Mod;return *this;}
    mint operator++(int) noexcept {mint m = *this;a += 1;if (a >= Mod) a -= Mod;return m;}
    mint &operator-=(const mint rhs) noexcept {if (a < rhs.a) a += Mod;a -= rhs.a;return *this;}
    mint &operator--() noexcept {if (a < 0) a += Mod;a -= 1;return *this;}
    mint operator--(int) noexcept {mint m = *this;if (a < 0) a += Mod;a -= 1;return m;}
    mint &operator*=(const mint rhs) noexcept {a = a * rhs.a % Mod;return *this;}
    mint &operator/=(mint rhs) noexcept {u64 exp = Mod - 2;while(exp) {if(exp % 2) {*this *= rhs;}rhs *= rhs;exp /= 2;}return *this;}
    operator long long() const {return a;}
    friend ostream& operator<< (ostream& os, const mint &m) {os << m.a;return os;};
    friend istream& operator>> (istream& is, mint &m) {long long l;is >> l;m.set(l);return is;};
};

// 正方行列
template <size_t N,typename R>
class SqMatrix {
public:
    using arr = array<R, N>;
    using mat = array<arr, N>;
    mat dat;
    SqMatrix() {
        rep(i, N) rep(j, N) dat[i][j] = R::add_identity();
    }
    SqMatrix& operator=(const SqMatrix& a) {
        dat = a.dat;
        return (*this);
    }
    bool operator==(const SqMatrix& a) {
        return dat == a.dat;
    }
    static SqMatrix add_id() {
        return SqMatrix();
    }
    static SqMatrix mul_id() {
        SqMatrix res;
        rep(i, N) res[i][i] = R::mul_identity();
        return res;
    }
    size_t size() const {return (N);}
    arr& operator[](size_t k) {return dat[k];}
    const arr& operator[](size_t k) const {return dat[k];}
    SqMatrix operator*(const SqMatrix& a) {
        SqMatrix res;
        rep(i, N) rep(j, N) rep(k, N) res[i][j] = res[i][j] + (dat[i][k] * a[k][j]);
        return res;
    }
    SqMatrix operator+(const SqMatrix& a) {
        SqMatrix res;
        rep(i, N) rep(j, N) res[i][j] = dat[i][j] + a[i][j];
        return res;
    }
    SqMatrix pow(ll n) {
        SqMatrix a=*this, res = mul_id();
        while(n) {
            if(n & 1) res = res * a;
            a = a * a;
            n >>= 1;
        }
        return res;
    }
    friend ostream& operator<< (ostream& os, const SqMatrix &m) {
        rep(i, N) {
            rep(j, N) {
                os << m.dat[i][j] << " ";
            }
            if (i != N - 1) os << endl;
        }
        return os;
    }
};

void solve() {
    ll L;ll A, B;
    cin >> L >> A >> B >> Mod;
    //L = 4;A=8;B= 1;Mod=1000000;
    auto p = [&](ll d) {
        auto nd = [&](ll _d){if(_d==0)return 0LL;return min(L, max(0LL, ((ll)pow(10, _d) - A + B -1) / (B)));};
        return nd(d) - nd(d - 1);
    };
    SqMatrix<3, mint> m, n = SqMatrix<3, mint>::mul_id();
    array<mint, 3> arr = {0, A, 1}, newarr;
    rep(i, 1, 18) {
        m[0][0] = (ll)pow(10, i) % Mod;
        m[1][1] = 1;
        m[2][2] = 1;
        m[0][1] = 1;
        m[1][2] = B % Mod;
        n = m.pow(p(i)) * n;
    }
    newarr[0] = n[0][0] * arr[0] + n[0][1] * arr[1] + n[0][2] * arr[2];
    out(newarr[0] % Mod);
}

signed main() {
    presolve(20);
    solve();
    return 0;
}

Measured memory_bytes: 384