#include<bits/stdc++.h>
using namespace std;
int mod;const int Lucina=2;
void plusle(int &a,int b){
    a+=b;if(a>=mod)a-=mod; return;
}
void minun(int &a,int b){
    a-=b; if(a<0)a+=mod; return;
}
int add(int a,int b) {
  a+=b;
  return a>=mod?a-mod:a;
}
int sub(int a,int b) {
  a-=b;
  return a<0?a+mod:a;
}
int mul(int a,int b) {
  return (int)((long long)a*b%mod);
}
int power(int a,int b) {
  int res=1;
  while (b>0) {
    if (b&1) {
      res=mul(res,a);
    }
    a=mul(a,a);
    b>>=1;
  }
  return res;
}
struct matrix{
    int m[3][3];
    matrix (){
        memset(m,0,sizeof(m));
    }
    void print(){
        for(int i=0;i<=Lucina;i++)
            for(int j=0;j<=Lucina;j++)
            printf("%d%c",m[i][j],j==Lucina?'\n':' ');
    }
    int* operator [] (int r) {
        return m[r];
    }

    matrix I(){
        matrix tmp;
        for(int i=0;i<=Lucina;i++)
            tmp[i][i]=1;
        return tmp;
    }
    friend matrix operator +( matrix x, matrix y){
        matrix tmp;
        for(int i=0;i<=Lucina;i++)
            for(int j=0;j<=Lucina;j++)
            tmp[i][j]=add(x[i][j],y[i][j]);
        return tmp;
    }
    friend matrix operator *( matrix x, matrix y){
        matrix tmp;
        for(int i=0;i<=Lucina;i++)
        for(int j=0;j<=Lucina;j++){
            for(int r=0;r<=Lucina;r++){
                tmp[i][j]=add(tmp[i][j],mul(x[i][r],y[r][j]));
            }
        }
        return tmp;
    }
    matrix power(matrix x,long long b){
        matrix tmp=I();
        while(b>0){
            if(b&1){
            tmp=(tmp*x);
            }
        x=(x*x);
        b>>=1;
        }
        return tmp;
    }
};

long long l,a,b;

int main(){
    scanf("%lld%lld%lld%d",&l,&a,&b,&mod);
    /**
    Arithmetic progressing with l terms
    First term is A and difference is b
    write them in
    A(A+B)(A+2*B) in other word, concatenate them
    Let the current number be X and we want to concatenate Y
    the new number is X*(10*d)+Y -> d is the number of digit of Y
    But don't forget that Y is just something like Y'+b
    |10^d 1 0| X'   X"
    | 0   1 b| Y'-> Y"
    | 0   0 1| 1 -> 1
    Since all number in arithmetic progressing is now over than 1e18
    So just brute force for 1-18
    **/
    matrix s;
    s[0][0]=(0);
    s[1][0]=(int)(a%mod);
    s[2][0]=1;
  //  s.print();
   // s.print();
    long long p=0LL;
    long long last=a+(l-1)*b;
    long long pre=0,now=0;
    long long sum=0;
    matrix t=s.I();
    for(int i=0;i<=17;i++){
        ///count how many number is in arithmetic progression from
        ///10^i->10^(i+1)-1
        p++;
        p*=10LL;p--;
        bool out=false;
        if(p>last){
            out=true;
        }
        ///7 3 4
       /// cout<<(p-a)<<' ';
        now=max(0LL,(min(p,last)-a)/b+1);
        if(now-pre<=0){
            pre=now;
            if(out)break;
            continue;
        }
        long long many=now-pre;
        sum+=many;
        //cout<<i<<' '<<many<<' '<<now<<' '<<pre<<'\n';
        matrix c;
        c[0][0]=(int)((p+1)%mod);
        c[0][1]=1;c[1][1]=1;c[1][2]=(b%mod);c[2][2]=1;
       // cout<<"LUCINA\n";
       // c.print();
       // c.print();
      //  cout<<"******************************\n";
        c=c.power(c,many);
       // c.print();
      //  cout<<"..............................\n";
        t=c*t;
        //s.print();
        //cout<<"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n";
        pre=now;
        if(out)break;
        }
        s=t*s;
    assert(sum==l);
   // s.print();
    printf("%d\n",s[0][0]);
}


Measured memory_bytes: 256