#include<bits/stdc++.h>
using namespace std;
#define MD 1000000007
void *wmem;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
struct modint{
  static unsigned md;
  unsigned val;
  modint(){
  }
  modint(int a){
    val = ord(a);
  }
  modint(unsigned a){
    val = ord(a);
  }
  modint(long long a){
    val = ord(a);
  }
  modint(unsigned long long a){
    val = ord(a);
  }
  void setmod(unsigned m){
    md = m;
  }
  unsigned ord(unsigned a){
    return a%md;
  }
  unsigned ord(int a){
    a %= md;
    if(a < 0){
      a += md;
    }
    return a;
  }
  unsigned ord(unsigned long long a){
    return a%md;
  }
  unsigned ord(long long a){
    a %= md;
    if(a < 0){
      a += md;
    }
    return a;
  }
  unsigned get(){
    return val;
  }
  modint &operator+=(modint a){
    val += a.val;
    if(val >= md){
      val -= md;
    }
    return *this;
  }
  modint &operator-=(modint a){
    if(val < a.val){
      val = val + md - a.val;
    }
    else{
      val -= a.val;
    }
    return *this;
  }
  modint &operator*=(modint a){
    val = ((unsigned long long)val*a.val)%md;
    return *this;
  }
  modint &operator/=(modint a){
    return *this *= a.inverse();
  }
  modint operator+(modint a){
    return modint(*this)+=a;
  }
  modint operator-(modint a){
    return modint(*this)-=a;
  }
  modint operator*(modint a){
    return modint(*this)*=a;
  }
  modint operator/(modint a){
    return modint(*this)/=a;
  }
  modint operator+(int a){
    return modint(*this)+=modint(a);
  }
  modint operator-(int a){
    return modint(*this)-=modint(a);
  }
  modint operator*(int a){
    return modint(*this)*=modint(a);
  }
  modint operator/(int a){
    return modint(*this)/=modint(a);
  }
  modint operator+(long long a){
    return modint(*this)+=modint(a);
  }
  modint operator-(long long a){
    return modint(*this)-=modint(a);
  }
  modint operator*(long long a){
    return modint(*this)*=modint(a);
  }
  modint operator/(long long a){
    return modint(*this)/=modint(a);
  }
  modint operator-(void){
    modint res;
    if(val){
      res.val=md-val;
    }
    else{
      res.val=0;
    }
    return res;
  }
  operator bool(void){
    return val!=0;
  }
  operator int(void){
    return get();
  }
  operator long long(void){
    return get();
  }
  modint inverse(){
    int a=val, b=md, t, u=1, v=0;
    modint res;
    while(b){
      t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    if(u < 0){
      u += md;
    }
    res.val = u;
    return res;
  }
  modint pw(unsigned long long b){
    modint a(*this), res;
    res.val = 1;
    while(b){
      if(b&1){
        res *= a;
      }
      b >>= 1;
      a *= a;
    }
    return res;
  }
  bool operator==(int a){
    return ord(a)==val;
  }
  bool operator!=(int a){
    return ord(a)!=val;
  }
}
;
modint operator+(int a, modint b){
  return modint(a)+=b;
}
modint operator-(int a, modint b){
  return modint(a)-=b;
}
modint operator*(int a, modint b){
  return modint(a)*=b;
}
modint operator/(int a, modint b){
  return modint(a)/=b;
}
modint operator+(long long a, modint b){
  return modint(a)+=b;
}
modint operator-(long long a, modint b){
  return modint(a)-=b;
}
modint operator*(long long a, modint b){
  return modint(a)*=b;
}
modint operator/(long long a, modint b){
  return modint(a)/=b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(modint x){
  int i;
  i = (int)x;
  wt_L(i);
}
template<class T> struct Matrix{
  T *dat;
  int c, mem, r;
  Matrix(){
    r=c=mem = 0;
  }
  Matrix(const int rr, const int cc){
    if(rr == 0 || cc == 0){
      r = c = 0;
    }
    else{
      r = rr;
      c = cc;
    }
    mem = r * c;
    if(mem > 0){
      dat = new T[mem];
    }
  }
  Matrix(const Matrix<T> &a){
    int i;
    r = a.r;
    c = a.c;
    mem = r * c;
    dat = new T[mem];
    for(i=0;i<mem;i++){
      dat[i] = a.dat[i];
    }
  }
  ~Matrix(){
    if(mem){
      delete [] dat;
    }
  }
  void changeSize(const int rr, const int cc){
    if(rr==0 || cc==0){
      r = c = 0;
    }
    else{
      r = rr;
      c = cc;
    }
    if(mem < r*c){
      if(mem){
        delete [] dat;
      }
      mem = r*c;
      dat = new T[mem];
    }
  }
  Matrix<T>& operator=(const Matrix<T> &a){
    int i, j;
    r = a.r;
    c = a.c;
    mem = r * c;
    dat = new T[mem];
    for(i=0;i<mem;i++){
      dat[i] = a.dat[i];
    }
    return *this;
  }
  Matrix<T>& operator=(const int a){
    int i, j;
    j = r * c;
    for(i=0;i<j;i++){
      dat[i] = 0;
    }
    j =min_L(r, c);
    for(i=0;i<j;i++){
      dat[i*c+i] = a;
    }
    return *this;
  }
  Matrix<T>& operator+=(const Matrix<T> &a){
    int i, j;
    if(r==0 || r!=a.r || c!=a.c){
      changeSize(0,0);
      return *this;
    }
    j = r*c;
    for(i=0;i<j;i++){
      dat[i] += a.dat[i];
    }
    return *this;
  }
  Matrix<T> operator+(const Matrix<T> &a){
    return Matrix<T>(*this) += a;
  }
  Matrix<T>& operator-=(const Matrix<T> &a){
    int i, j;
    if(r==0 || r!=a.r || c!=a.c){
      changeSize(0,0);
      return *this;
    }
    j = r*c;
    for(i=0;i<j;i++){
      dat[i] -= a.dat[i];
    }
    return *this;
  }
  Matrix<T> operator-(const Matrix<T> &a){
    return Matrix<T>(*this) -= a;
  }
  Matrix<T>& operator*=(const Matrix<T> &a){
    T *m;
    int i, j, k, x;
    if(r==0 || c!=a.r){
      changeSize(0,0);
      return *this;
    }
    m = (T*)wmem;
    x = r * a.c;
    for(i=0;i<x;i++){
      m[i] = 0;
    }
    for(i=0;i<r;i++){
      for(k=0;k<c;k++){
        for(j=0;j<a.c;j++){
          m[i*a.c+j] += dat[i*c+k] * a.dat[k*a.c+j];
        }
      }
    }
    changeSize(r, a.c);
    for(i=0;i<x;i++){
      dat[i] = m[i];
    }
    return *this;
  }
  Matrix<T> operator*(const Matrix<T> &a){
    return Matrix<T>(*this) *= a;
  }
  Matrix<T>& operator*=(const int a){
    int i, j;
    j = r * c;
    for(i=0;i<j;i++){
      dat[i] *= a;
    }
    return *this;
  }
  Matrix<T>& operator*=(const long long a){
    int i, j;
    j = r * c;
    for(i=0;i<j;i++){
      dat[i] *= a;
    }
    return *this;
  }
  Matrix<T>& operator*=(const double a){
    int i, j;
    j = r * c;
    for(i=0;i<j;i++){
      dat[i] *= a;
    }
    return *this;
  }
  inline T* operator[](const int a){
    return dat+a*c;
  }
}
;
template<class T> Matrix<T> operator*(const int a, const Matrix<T> &b){
  return Matrix<T>(b)*=a;
}
template<class T> Matrix<T> operator*(const Matrix<T> &b, const int a){
  return Matrix<T>(b)*=a;
}
template<class T> Matrix<T> operator*(const long long a, const Matrix<T> &b){
  return Matrix<T>(b)*=a;
}
template<class T> Matrix<T> operator*(const Matrix<T> &b, const long long a){
  return Matrix<T>(b)*=a;
}
template<class T> Matrix<T> operator*(const double a, const Matrix<T> &b){
  return Matrix<T>(b)*=a;
}
template<class T> Matrix<T> operator*(const Matrix<T> &b, const double a){
  return Matrix<T>(b)*=a;
}
template<class T, class S> inline Matrix<T> pow_L(Matrix<T> a, S b){
  Matrix<T> res;
  int i, j;
  res.changeSize(a.r, a.c);
  res = 1;
  while(b){
    if(b&1){
      res *= a;
    }
    b >>= 1;
    a *= a;
  }
  return res;
}
template<class T, class S> inline T pow_L(T a, S b){
  T res=1;
  res = 1;
  while(b){
    if(b&1){
      res *= a;
    }
    b >>= 1;
    a *= a;
  }
  return res;
}
char memarr[96000000];
unsigned modint::md;
long long L;
long long A;
long long B;
int M;
int main(){
  Matrix<modint> mt, vc;
  long long i, j, k, p;
  modint res;
  wmem = memarr;
  {
    modint x;
    x.setmod(MD);
  }
  rd(L);
  rd(A);
  rd(B);
  rd(M);
  res.setmod(M);
  mt.changeSize(3,3);
  vc.changeSize(3,1);
  vc[0][0] = 0;
  vc[1][0] = A;
  vc[2][0] = B;
  p = 1;
  while(L){
    p *= 10;
    if(A >= p){
      continue;
    }
    k =min_L(L, (p-1-A)/B+1);
    L -= k;
    A += k*B;
    mt = 0;
    mt[0][0] = p;
    mt[0][1] = mt[1][1] = mt[1][2] = mt[2][2] = 1;
    vc = (pow_L(mt,k)) * vc;
  }
  res = vc[0][0];
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190706-1

// --- original code ---
// ll L, A, B;
// int M;
// {
//   ll i, j, k;
//   ll p;
//   modint res;
//   Matrix<modint> mt, vc;
//   
//   rd(L,A,B,M);
//   res.setmod(M);
// 
//   mt.changeSize(3,3);
//   vc.changeSize(3,1);
//   vc[0][0] = 0;
//   vc[1][0] = A;
//   vc[2][0] = B;
// 
//   p = 1;
//   while(L){
//     p *= 10;
//     if(A >= p) continue;
//     k = min(L, (p-1-A)/B+1);
//     L -= k;
//     A += k*B;
//     
//     mt = 0;
//     mt[0][0] = p;
//     mt[0][1] = mt[1][1] = mt[1][2] = mt[2][2] = 1;
// 
//     vc = (mt ** k) * vc;
//   }
// 
//   res = vc[0][0];
//   wt(res);
// }


Measured memory_bytes: 384