#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define REP(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back
#define lint ll
typedef long double ld;
typedef complex<ld> cd;
ll MOD;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;

vector<vector<lint>> matmul(const vector<vector<lint>> &A, const vector<vector<lint>> &B, lint mod=MOD){
    int H = A.size(), W = B[0].size(), K = B.size();
    vector<vector<lint>> C(H, vector<lint>(W));
    REP(i, H) REP(j, W) REP(k, K) (C[i][j] += A[i][k] * B[k][j]) %= mod;
    return C;
}
vector<vector<lint>> matpower(vector<vector<lint>> X, lint n, lint mod=MOD){
    vector<vector<lint>> res(X.size(), vector<lint>(X.size()));
    REP(i, res.size()) res[i][i] = 1;
    while (n)
    {
        if (n & 1) res = matmul(res, X, mod);
        X = matmul(X, X, mod); n >>= 1;
    }
    return res;
}
lint power(lint x, lint n){
    lint ans = 1;
    while (n>0)
    {
        if (n & 1) (ans *= x) %= MOD;
        (x *= x) %= MOD;
       n >>= 1;
    }
   return ans;
}

ll sol(ll len,ll A,ll B,ll amari){
    if(!len){
        return amari;
    }
    ll d=to_string(A).length();
    ll m=1;
    F0R(i,d){
        m*=10;
    }
    ll n_term=min((m-1-A)/B+1,len);
    vector<vector<ll>> trans{{power(10,d),0,0},{1,1,0},{0,B,1}};
    trans=matpower(trans,n_term);
    amari=(trans[0][0]*(amari%MOD)%MOD+trans[1][0]*(A%MOD)%MOD+1*trans[2][0]%MOD)%MOD;
    return sol(len-n_term,A+B*n_term,B,amari);
    
}




void solve(){
    ll l,A,B;
    cin>>l>>A>>B>>MOD;
    ll ret=sol(l,A,B,0);
    out(ret);
}

int main(){
    solve();
    return 0;
}