#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD M

ll L,A,B,M;

struct BSPLmatrix
{
    //ll A;
    ll a_a;
    ll a_b;
    ll b;
    ll c;
    ll p;
};


ll retll10(int n){
  ll ans=1LL;
  REP(i,n)ans*=10LL;
  return ans;
}

//   a/b mod c
ll moddiv(ll a,ll b){
	ll x0=MOD,x1=b,x2,n0=0LL,n1=1LL,n2,t=a%b,m,ans;
	if (t==0) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=(n0-m*n1)%MOD;
      if (x2==1){
        ans=(n2+MOD)%MOD;
        break;
      }
      x0=x1;x1=x2;
      n0=n1;n1=n2;
    }
	return (a+((t*ans)%MOD)*b-t)/b;
}
//剰余の割ざん

//aのn乗 mod c
ll expmod(ll a,ll n){
  ll ans=1LL,aa=a,beki=n;
  for(int i=0;i<64;i++){
    if (beki%2==1) ans=ans*aa%MOD;
    aa=aa*aa%MOD;
    beki/=2;
    if (beki==0)break;
  }
  return ans;
}




int main(){
  cin >> L >> A>>B>>M;
  ll t=A+B*(L-1);
  ll ans=0LL;
  //cout<<t<<endl;
  
  double dA=A;
  double dB=B;
  double dL=L;
  double dLk;
  double keta=(log(dA/dB+dL)+log(dB))/log(10);
  int iketa=int(keta);
  
  vector<ll> iLs(iketa+1);
  vector<ll> iLe(iketa+1);
  iLe[iketa]=L-1;
  iLs[0]=0;
  //cout<<iketa<<endl;
  for(int i=iketa;i>0;i--){
    dLk=(retll10(i)-1-dA)/dB;
    ll ldLk=(ll)dLk;
    ldLk+=200;
    while(retll10(i)<(1+A+B*ldLk)){
      ldLk--;
    }
    if (ldLk<0)ldLk=-1;

    iLe[i-1]=min(ldLk,L-1);
    iLs[i]=(ll)iLe[i-1]+1;
  }
  
  /*
  for(int i=0;i<iketa+1;i++){
    cout<<iLs[i]<<endl;
    cout<<iLe[i]<<endl;
    cout<<(A+B*iLe[i])<<" "<<(A+B*(iLs[i]))<<endl;
    //cout<<endl;
  }
  return 0;
   */
  
  //cout<<iL[i-1]<<" "<<(A+B*iLe[i-1])<<" "<<(A+B*(iLs[i-1]+1))<<endl;


  
  vector<BSPLmatrix> bsplmt(36);int wid=0;
  ll geta=1LL;
  for(int i=iketa;i>=0;i--){
    ll end=iLe[i];
    if (end==-1LL)break;
    ll start=iLs[i];
    //今計算してるとのろの桁
    /*
    cout<<"i="<<i<<endl;
    cout<<"start="<<start<<endl;
    cout<<"end="<<end<<endl;
     */
    /*
    t=A+B*start;
    cout<<t<<" "<<(A+B*end)<<endl;
     */
    
    
    ll loop=end-start+1;//バイナリスプリッティングで統合する数
    if (loop<=0)continue;
    
    BSPLmatrix mtnow;
    mtnow.a_a=(A%M+(B%M)*start)%M;
    mtnow.a_b=B%M;
    //mtnow.A=(A%M+(B%M)*start)%M;
    mtnow.c=1LL;
    mtnow.b=retll10(i+1)%M;
    mtnow.p=retll10(i+1)%M;
    for(ll lp=loop;;){
      if (lp%2LL==1LL){
        bsplmt[wid]=mtnow;wid++;
        mtnow.a_a=(mtnow.a_b+mtnow.a_a)%M;
        if (lp==1LL)break;
      }
      ll tmp=mtnow.a_a*(mtnow.p+1)+mtnow.a_b;
      tmp%=M;
      mtnow.a_b=mtnow.a_b*2*(mtnow.p+1)%M;
      mtnow.a_a=tmp;
      mtnow.b=mtnow.b*mtnow.b%M;
      mtnow.c=mtnow.c*mtnow.c%M;
      mtnow.p=mtnow.p*mtnow.p%M;
      lp=lp/2LL;
    }
    //行列を追加した逆順にかけていく
    BSPLmatrix mtnow_0,mtnow_1;
    mtnow_0=bsplmt[wid-1];wid--;
    for(int j=0;j<18*2;j++){
      if (wid==0)break;
      mtnow_1=bsplmt[wid-1];wid--;
      mtnow_0.a_a=(mtnow_0.b*mtnow_1.a_a%M+mtnow_0.a_a*mtnow_1.c%M)%M;
      mtnow_0.b=mtnow_0.b*mtnow_1.b%M;
      mtnow_0.c=mtnow_0.c*mtnow_1.c%M;
    }
    ll bsplres=moddiv(mtnow_0.a_a%M,mtnow_0.c)%M;
    //cout<<bsplres<<endl;
    ans=(ans+bsplres*geta%M)%M;
    geta=geta*expmod(retll10(i+1)%M,loop)%M;
    
    /*
    t=A+B*(iL[i-1]);
    cout<<t<<"("<<iL[i-1]<<") "<<(t+B)<<endl;
    */
  }
    
  /*
  cout<<keta<<endl;
  cout<<exp(keta*log(10))<<endl;
  cout<<t<<endl;
  */
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256