#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <cassert>
#include <numeric>
#include <random>


using namespace std;
typedef long long ll;
typedef unsigned long long ull;

ll a, b, r, m;

inline ll mul(ll x, ll y) {
  if (x > m) x %= m;
  if (y > m) y %= m;
  return (x * y) % m;
}

inline ll add(ll x, ll y) {
  if (x > m) x %= m;
  if (y > m) y %= m;
  ll s = (x + y) % m;
  if (s < 0) return s + m;
  return s;
}

int check(ll i) {
  if (i == -1) return 0;
  ll x = a + b * i;
  assert(x < 1000000000000000000LL);
  int res = 0;
  while (x) {
    x /= 10;
    res++;
  }
  return res;
}

ll pot(ll base, ull expo) {
  if (expo == 0) return 1;
  ll y = pot(base, expo / 2);
  y = mul(y, y);
  if (expo & 1) return mul(y, base);
  return y;
}

// (1 + x + x^2 + ... + x^n) % m
ll geo_sum(ll n, ll x) {
  if (n == 0) return 1;
  if (n&1) {
    ll y = geo_sum(n/2, mul(x, x));
    return mul(add(1, x), y);
  } 
  ll z = pot(x, n);
  ll y = geo_sum(n-1, x);
  return add(z, y);
}

// d/dx {geo_sum(n, x)}
ll geo_sum_dif(ll n, ll x) {
  if (n == 0) return 0;
  if (n&1) {
    ll s1 = geo_sum(n/2, mul(x,x));
    ll s2 = mul(mul(2, x), geo_sum_dif(n/2, mul(x, x)));
    s2 = mul(add(1,x), s2);
    return add(s1, s2);
  }
  ll s1 = geo_sum_dif(n-1, x);
  ll s2 = mul(n, pot(x, n-1));
  return add(s1, s2);
}

// x + 2x^2 + 3x^3 + ... + nx^n
ll special_sum(ll n, ll x) {
  ll y = geo_sum_dif(n, x);
  return mul(x, y);
}


ll go1(int len) {
  ll lo = -1;
  ll hi = r-1;
  while (hi - lo > 1) {
    ll mid = (lo + hi) / 2;
    if (check(mid) < len) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  if (check(hi) == len) return hi;
  return r;
}

ll go2(ll lo, ll hi, ll init_expo, ull len) {
  if (lo == hi) return 0;
  ll aux_10 = pot(10, init_expo);
  ll f1 = mul(a, aux_10);
  ll f2 = mul(b, aux_10);
  ll c = pot(10, len);
  // ll g1 = 0;
  // for (ll i = 0; i < hi-lo; i++) { g1 += pot(c, i); g1 %= m; }
  ll g1 = geo_sum(hi-1-lo, c);
  ll d = add(lo, hi-1);
  ll g21 = mul(g1, d);
  // ll g221 = 0;
  // for (ll i = 0; i < hi-lo; i++) { g221 += (i * pot(c, i)) % m; g221 %= m; }
  ll g221 = special_sum(hi-1-lo, c);
  ll g222 = mul(lo, g1);

  ll sum = add(g221, g222);
  ll dif = add(g21, -sum);
  // cerr << f1 << "  " << g1 << " " << f2 << " " << dif << endl;
  return add(mul(f1, g1), mul(f2, dif));
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> r >> a >> b >> m;

  vector<pair<ll, ll>> stops;
  for (int i = 1; i <= 18; i++) {
    ll idx = go1(i);
    // cerr << "for len " << i << ", start at: " << idx << endl;
    if (idx != r) stops.push_back({idx, i});
  }
  stops.push_back({r, r});

  ull tot = 0;
  for (int i = 0; i+1 < stops.size(); i++) {
    ull cant = stops[i+1].first - stops[i].first;
    ull len = stops[i].second;
    tot += len * cant;
  }

  ll res = 0;
  for (int i = 0; i+1 < stops.size(); i++) {
    ull len = stops[i].second;
    // cerr << "len: " << len << endl;
    tot -= (stops[i+1].first - stops[i].first) * len;
    // cerr << "tot: " << tot << endl;
    ll aux = go2(stops[i].first, stops[i+1].first, tot, len);
    // cerr << "from [" << stops[i].first << ", " << stops[i+1].first << ") -> " << aux << endl;
    res = add(res, aux);
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3612