#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (auto i=(a); i<(b); ++i)
#define iter(it,c) for (auto it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
const int INF = 2147483647;

ll MOD;

template <class K> bool eq(K a, K b) { return a == b; }
template <class T> struct matrix {
  int rows, cols, cnt; vector<T> data;
  inline T& at(int i, int j) { return data[i * cols + j]; }
  matrix(int r, int c) : rows(r), cols(c), cnt(r * c) {
    data.assign(cnt, T(0)); }
  matrix(const matrix& other) : rows(other.rows),
    cols(other.cols), cnt(other.cnt), data(other.data) { }
  T& operator()(int i, int j) { return at(i, j); }
  matrix<T> operator +(const matrix& other) {
    matrix<T> res(*this); rep(i,0,cnt)
      res.data[i] += other.data[i]; return res; }
  matrix<T> operator -(const matrix& other) {
    matrix<T> res(*this); rep(i,0,cnt)
      res.data[i] -= other.data[i]; return res; }
  matrix<T> operator *(T other) {
    matrix<T> res(*this);
    rep(i,0,cnt) res.data[i] *= other; return res; }
  matrix<T> operator *(const matrix& other) {
    matrix<T> res(rows, other.cols);
    rep(i,0,rows) rep(k,0,cols) rep(j,0,other.cols) {
      res(i, j) = (res(i, j) + at(i, k) * other.data[k * other.cols + j] % MOD) % MOD;
    }
    return res; }
  matrix<T> pow(ll p) {
    matrix<T> res(rows, cols), sq(*this);
    rep(i,0,rows) res(i, i) = T(1);
    while (p) {
      if (p & 1) res = res * sq;
      p >>= 1;
      if (p) sq = sq * sq;
    } return res; }
  matrix<T> rref(T &det, int &rank) {
    matrix<T> mat(*this); det = T(1), rank = 0;
    for (int r = 0, c = 0; c < cols; c++) {
      int k = r;
      rep(i,k+1,rows) if (abs(mat(i,c)) > abs(mat(k,c))) k = i;
      if (k >= rows || eq<T>(mat(k, c), T(0))) continue;
      if (k != r) {
        det *= T(-1);
        rep(i,0,cols) swap(mat.at(k, i), mat.at(r, i));
      } det *= mat(r, r); rank++;
      T d = mat(r,c);
      rep(i,0,cols) mat(r, i) /= d;
      rep(i,0,rows) {
        T m = mat(i, c);
        if (i != r && !eq<T>(m, T(0)))
          rep(j,0,cols) mat(i, j) -= m * mat(r, j);
      } r++;
    } return mat; }
  matrix<T> transpose() {
    matrix<T> res(cols, rows);
    rep(i,0,rows) rep(j,0,cols) res(j, i) = at(i, j);
    return res; } };
// vim: cc=60 ts=2 sts=2 sw=2:

ll smod(ll a, ll b) {
    return (a % b + b) % b;
}

template <class T>
T mod_pow(T b, T e, T m) {
  T res = T(1);
  while (e) {
    if (e & T(1)) res = smod(res * b, m);
    b = smod(b * b, m), e >>= T(1); }
  return res; }

ll calc(ll l, ll r, ll a, ll b, ll p, ll m) {
    // cout << l << " " << r << endl;

    matrix<ll> mat(3,3);

    mat(0,0) = p%m;
    mat(0,2) = (m-(b%m)*(p%m)%m)%m;
    mat(1,0) = p%m;
    mat(1,1) = 1;
    mat(1,2) = (m-(b%m)*(p%m)%m)%m;
    mat(2,2) = p%m;

    matrix<ll> init(3,1);
    init(0,0) = (a+(b%m)*(r%m))%m;
    init(1,0) = (a+(b%m)*(r%m))%m;
    init(2,0) = 1;

    mat = mat.pow(r-l) * init;

    ll ans = mat(1,0);

    // ll na = 0;
    // for (ll i = l; i <= r; i++) {
    //     // cout << (a+b*i) << " " << r-i  << " " << mod_pow(p,r-i, m) << " " << m << endl;
    //     na += (a+(b%m)*(i%m)%m)%m * mod_pow(p,r-i, m) % m;
    //     na %= m;
    // }
    // return na;

    return ans;
}

int main() {
    ll l, a, b, m;
    cin >> l >> a >> b >> m;
    MOD = m;

    ll ans = 0;
    __int128 P = 1;
    for (int k = 0; k <= 20; k++, P *= 10) {
        ll lo = 0,
                 hi = l-1,
                 res = -1;
        while (lo <= hi) {
            ll mid = (lo+hi)/2;
            if (a + (__int128)b*mid >= P) {
                res = mid;
                hi = mid-1;
            } else {
                lo = mid+1;
            }
        }

        if (res == -1) continue;

        ll res2 = -1;
        lo = res;
        hi = l-1;
        while (lo <= hi) {
            ll mid = (lo+hi)/2;
            if (a + (__int128)b*mid < P*10) {
                res2 = mid;
                lo = mid+1;
            } else {
                hi = mid-1;
            }
        }

        if (res2 == -1) continue;

        ans = ans * mod_pow((ll)((P*10)%m), res2-res+1, m) % m;
        ans = (ans + calc(res, res2, a, b, P*10, m)) % m;

        // cout << k << " " << res << " " << res2 << " " << calc(res, res2, a, b, P*10, m) << endl;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256