#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll =unsigned  long long;
#define int ll 
const ll longinf=1LL<<60 ;
ll mod;


ll powmod(ll n,ll k){
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

template<typename T>
struct Matrix{
    int h,w;
    vector<T> a;
    Matrix(int n_=0):h(n_),w(n_),a(n_*n_){}
    Matrix(int n_, int m_):h(n_),w(m_),a(n_*m_){}
    Matrix(int n_, int m_, vector<T> a_):h(n_),w(m_),a(a_){}
    T& get(int r,int c){return a[r*w+c];}
    T get(int r,int c)const{return a[r*w+c];}

    Matrix& operator+=(const Matrix& m) {
        assert(h == m.h && w == m.w);
        for (int i = 0; i < w*h; ++i)a[i] += m.a[i];
    }
    Matrix& operator-=(const Matrix& m) {
        assert(h == m.h && w == m.w);
        for (int i = 0; i < w*h; ++i)a[i] -= m.a[i];
    }
    Matrix& operator*=(const Matrix& m) {
        assert(w == m.h);
        Matrix ret(h, m.w);
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < m.w; ++j) {
                for (int k = 0; k < w; ++k) {
                    ret.a[i * m.w + j] += a[i * w + k] * m.a[k * m.w + j]%mod;
                }
            ret.a[i * m.w + j] %= mod;
            }
        }
        return (*this) = ret;
    }
    Matrix operator+(const Matrix& m) const { return Matrix(*this) += m; }
    Matrix operator-(const Matrix& m) const { return Matrix(*this) -= m; }
    Matrix operator*(const Matrix& m) const { return Matrix(*this) *= m; }
};
template<typename T>
Matrix<T> unit(int n){
    Matrix<T> ret(n);
    rep(i,n)ret.get(i,i)=1;
    return ret;
}
template<typename T>
Matrix<T> matpow(Matrix<T> a,ll n){
    assert(a.h==a.w);
    Matrix<T> ret=unit<T>(a.h);
    while(n){
        if(n&1)ret*=a;
        a*=a;
        n>>=1;
    }
    return ret;
}
signed main(){
    ll l, a, b;
    cin>>l>>b>>a>>mod;
    vector<ll> x(19);
    ll d = 1;
    rep(i,19){
        if(d>=1e17)x[i+1]=l;
        else {
            ll nxt=10*d-1;
            if(nxt>=b)x[i+1]=1+(nxt-b)/a;
        }
        if(x[i+1]>=l){
            REP(j,i,18)x[j+1]=l;
            break;
        }
        d*=10;
    }
    a%=mod;b%=mod;
    vector<ll> cnt(18);
    vector<ll> ret(18);
    rep(i,18){
        cnt[i] = x[i+1]-x[i];
        if(cnt[i]==0)continue;
        if(cnt[i]==1){
            ret[i]=(a*x[i]+b)%mod;
            continue;
        }
        Matrix<ll> mat(3,3);
        mat.get(0,0) = (powmod(10,i+1)+1)%mod;
        mat.get(0,1) = (mod-powmod(10,i+1))%mod;
        mat.get(0,2) = 1;
        mat.get(1,0) = 1;
        mat.get(2,2) = 1;
        auto res = matpow(mat,cnt[i]-1);
        ret[i] = res.get(0,0)*((a*x[i]+b)%mod) + res.get(0,2)*a%mod;
        ret[i]%=mod;
    }
    ll len = 1;
    ll ans=0;
    for(int j = 0;j<=17;++j){
        int i = 17 - j;
        ans += ret[i]*len%mod;
        ans%=mod;
        rep(j,i+1){
            len = len * powmod(10,cnt[i])%mod;
        }
        ans%=mod;
    }
    cout<<ans%mod<<endl;
    return 0;
}


Measured memory_bytes: 256