#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

struct mint {
  long long mod, x;
  mint(long long mod, long long x=0): mod(mod), x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

ll po(ll k, unsigned long long x, ll mod) {
  ll ret = 1;
  while (x) {
    if (x & 1) {
      ret = ret * k % mod;
    }
    k = k * k % mod;
    x >>= 1;
  }
  return ret;
}

int calc_digit(ll x) {
  int cnt = 0;
  while (x > 0) {
    x /= 10;
    cnt += 1;
  }
  return cnt;
}

void debug_(vvec<mint> & a) {
  vvll b(3, vll(3, 0));
  rep (i, 3) {
    rep (j, 3) {
      b[i][j] = a[i][j].x;
    }
  }
  debug(b);
}

vvec<mint> mult(vvec<mint> & a, vvec<mint> & b) {
  vvec<mint> ret(3, vector<mint>(3, mint(a[0][0].mod, 0)));
  rep (i, 3) {
    rep (j, 3) {
      rep (k, 3) {
        ret[i][j] += a[i][k] * b[k][j];
        if (b[0][0].x == 871938225) {
          debug3(i, j, ret[i][j].x);
        }
      }
    }
  }
  if (b[0][0].x == 871938225) {
    debug_(a);
    debug_(b);
    debug_(ret);
  }
  return ret;
}

vvec<mint> po(vvec<mint> k, ll x) {
  vvec<mint> ret(3, vector<mint>(3, mint(k[0][0].mod, 0)));
  rep (i, 3) {
    ret[i][i] += mint(k[0][0].mod, 1);
  }
  while (x) {
    if (x & 1) {
      ret = mult(ret, k);
    }
    k = mult(k, k);
    x >>= 1;
  }
  return ret;
}

vector<mint> mult(vector<mint> & a, vvec<mint> & b) {
  vector<mint> ret(3, mint(a[0].mod, 0));
  rep (i, 3) {
    rep (j, 3) {
      ret[i] += a[j] * b[j][i];
    }
  }
  return ret;
}

int DIGIT_MAX = 18;

int main() {
  ll l, a, b, m;
  scan(l, a, b, m);

  ll first_s = a;
  vll po10(DIGIT_MAX + 1, 0);
  po10[0] = 1;
  rep (i, DIGIT_MAX) {
    po10[i+1] = po10[i] * 10;
  }
  //debug(po10);
  vll separator = {0};
  rep (i, DIGIT_MAX) {
    int digit = i + 1;
    ll target = po10[digit] - 1;
    if (target - a < 0) {
      separator.push_back(0);
    } else {
      separator.push_back(min(l, (target - a) / b + 1));
    }
  }
  separator.push_back(l);
  //debug(separator);
  int sz = separator.size() - 1;
  assert(sz == DIGIT_MAX + 1);
  vvec<mint> mat(3, vector<mint>(3, mint(m, 0)));
  mat[1][0] = mint(m, 1);
  mat[1][1] = mint(m, 1);
  mat[2][1] = mint(m, b);
  mat[2][2] = mint(m, 1);
  vector<mint> state = {mint(m, 0), mint(m, a), mint(m, 1)};
  rep (i, sz) {
    int digit = i + 1;
    ll elm_count = separator[i+1] - separator[i];
    mat[0][0] = mint(m, po10[digit]);
    //debug2(digit, elm_count);
    //debug_(mat);
    vvec<mint> mat_c = po(mat, elm_count);
    /*
    vvec<mint> mat_c(3, vector<mint>(3, mint(m, 0)));
    rep (i, 3) {
      rep (j, 3) {
        mat_c[i][j] = mint(m, (i == j) ? 1 : 0);
      }
    }
    rep (i, elm_count) {
      mat_c = mult(mat_c, mat);
    }
    */
    state = mult(state, mat_c);
    //debug3(state[0].x, state[1].x, state[2].x);
    //debug_(mat_c);
  }
  print(state[0].x);

  return 0;
}


Measured memory_bytes: 384