#include <iostream>
#include <utility>
using namespace std;

__int128 mod_pow(__int128 x, __int128 k, __int128 mod){
  __int128 ret = 1;
  while(k){
    if(k&1) ret *= x, ret %= mod;
    x *= x, x %= mod;
    k >>= 1;
  }
  return ret;
}
 
pair<__int128, __int128> rec(__int128 x, __int128 k, __int128 mod){
  if(k == 1) return {1,0};
  pair<__int128,__int128> p = rec(x,k/2,mod);
  __int128 f = p.first, s = p.second;
  __int128 f_ = (f*(1+mod_pow(x,k/2,mod))%mod)%mod;
  if(k%2) f_ += mod_pow(x,k-1,mod), f_ %= mod;
  __int128 s_ = (s + (((s+(f*(k/2))%mod)%mod)*mod_pow(x,k/2,mod))%mod)%mod;
  if(k%2) s_ += (((k-1)%mod)*mod_pow(x,k-1,mod))%mod, s_ %= mod;
  f_ %= mod, s_ %= mod;
  return {f_,s_};
}

int main(){
  long long L_, A_, B_, M_;
  cin >> L_ >> A_ >> B_ >> M_;
  __int128 L = L_, A = A_, B = B_, M = M_;

  A += B*(L-1);
  B *= -1;

  constexpr int max_len = 18;
  
  __int128 s = 0;
  __int128 ans = 0;
  __int128 D[max_len+1];
  D[0] = 1;
  for(int k = 0; k < max_len; ++k) D[k+1] = (D[k]*10);

  __int128 prev_r = 0;
  for(int k = max_len; k >= 0; --k){
    __int128 d_ = D[k];
    if(d_ > A) continue;
    __int128 l = prev_r, r = (A-d_)/(-B) + 1;
    r = max(l,r);
    r = min(L,r);

    // cerr << k+1 << " " << l << " " << r << endl;
    // cerr << s << endl;
    
    if(l < r){
      pair<__int128,__int128> p = rec(mod_pow(10,k+1,M),r-l,M);
      __int128 t = (p.first*((A%M+(((B%M+M)%M)*(l%M))%M)%M))%M;
      t += (p.second*((B%M+M)%M))%M;
      t %= M;
      t *= mod_pow(10,s,M);
      ans += t%M;
      ans %= M;
      s += (r-l)*(k+1);
    }
    
    prev_r = r;
  }
  cout << (long long)ans << endl;
}
