#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct ModInt {
  using M = ModInt;
  unsigned v;
  static unsigned P;
  ModInt() : v(0) {}
  ModInt(auto x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool) *this; }
  M operator*(M r) const { return M(*this) *= r; }
  M operator/(M r) const { return M(*this) /= r; }
  M operator+(M r) const { return M(*this) += r; }
  M operator-(M r) const { return M(*this) -= r; }
  bool operator==(M r) const { return v == r.v; }
  bool operator!=(M r) const { return !(*this == r); }
  M& operator*=(M r) { v = (uint64_t) v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  M pow(auto n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  friend M operator*(auto l, M r) { return M(l) *= r; }
  friend M operator/(auto l, M r) { return M(l) /= r; }
  friend M operator+(auto l, M r) { return M(l) += r; }
  friend M operator-(auto l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; }
  friend bool operator==(auto l, M r) { return M(l) == r; }
  friend bool operator!=(auto l, M r) { return !(l == r); }
};
using Mint = ModInt;
unsigned Mint::P;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint l, a, b; cin >> l >> a >> b;
  a += b * (l - 1);
  cin >> Mint::P;
  V<lint> s(20);
  for (int x = 0; x < 20; ++x) {
    lint ng = -1, ok = l;
    while (ok - ng > 1) {
      lint mid = ng + ok >> 1;
      ((int)to_string(a - b * mid).size() <= x ? ok : ng) = mid;
    }
    s[x] = ok;
  }
  auto g = [&](const auto& g, Mint r, lint n) -> Mint {
    if (!n) return 0;
    if (n & 1) return 1 + r * g(g, r, n - 1);
    n >>= 1;
    return g(g, r, n) * (1 + r.pow(n));
  };
  auto fn = [&](const auto& fn, Mint A, Mint B, Mint r, lint n) -> Mint {
    if (!n) return 0;
    if (n & 1) return A + r * fn(fn, A + B, B, r, n - 1);
    n >>= 1;
    Mint res = fn(fn, A, B, r, n);
    res *= 1 + r.pow(n);
    res += g(g, r, n) * r.pow(n) * n * B;
    return res;
  };
  Mint res, o = 1;
  for (int x = 19; x; --x) if (s[x - 1]) {
    Mint r = Mint(10).pow(x);
    // Mint curr = -(a - b * s[x]) + (r.pow(s[x - 1] - s[x]) * b - r * b) / (r - 1) + r.pow(s[x - 1] - s[x]) * (a - b * (s[x - 1] - 1));
    // curr /= r - 1;
    Mint curr = fn(fn, a - b * s[x], -b, r, s[x - 1] - s[x]);
    res += curr * o;
    o *= r.pow(s[x - 1] - s[x]);
  }
  cout << res << '\n';
}

Measured memory_bytes: 256