#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

double mod(long n, long k) {
  return n % k >= 0 ? n % k : n % k + k;
}

void zero_mat(vector<vector<long>> &ass) {
  const long M = ass.size(), N = ass[0].size();
  for (long i = 0; i < M; i++) {
    for (long j = 0; j < N; j++) {
      ass[i][j] = 0;
    }
  }
}

void zero_vec(vector<long> &as) {
  const long N = as.size();
  for (long i = 0; i < N; i++) {
    as[i] = 0;
  }
}

void identity_mat(vector<vector<long>> &ass) {
  const long N = ass.size();
  for (long i = 0; i < N; i++) {
    for (long j = 0; j < N; j++) {
      ass[i][j] = i == j;
    }
  }
}

void copy_mat(const vector<vector<long>> &ass, vector<vector<long>> &bss) {
  const long M = ass.size(), N = ass[0].size();
  for (long i = 0; i < M; i++) {
    for (long j = 0; j < N; j++) {
      bss[i][j] = ass[i][j];
    }
  }
}

void copy_vec(const vector<long> &as, vector<long> &bs) {
  const long N = as.size();
  for (long i = 0; i < N; i++) {
    bs[i] = as[i];
  }
}

void mat_mult_mat(const vector<vector<long>> &ass,
                  const vector<vector<long>> &bss, vector<vector<long>> &css,
                  long num_mod) {
  const long L = ass.size(), M = ass[0].size(), N = bss[0].size();
  // initialize
  zero_mat(css);
  // calculate
  for (long i = 0; i < L; i++) {
    for (long k = 0; k < M; k++) {
      for (long j = 0; j < N; j++) {
        css[i][j] = mod(css[i][j] + ass[i][k] * bss[k][j], num_mod);
      }
    }
  }
}

void mat_mult_vec(const vector<vector<long>> &ass, const vector<long> &bs,
                  vector<long> &cs, long num_mod) {
  const long M = ass.size(), N = ass[0].size();
  zero_vec(cs);
  for (long i = 0; i < M; i++) {
    for (long j = 0; j < N; j++) {
      cs[i] = mod(ass[i][j] * bs[j] + cs[i], num_mod);
    }
  }
}

void mat_pow(const vector<vector<long>> &ass, long k, vector<vector<long>> &bss,
             long num_mod) {
  const long N = ass.size();
  // initialize
  identity_mat(bss);
  // calculate
  vector<vector<long>> xss(N, vector<long>(N, 0)), tss(N, vector<long>(N, 0));
  copy_mat(ass, xss);
  while (k > 0) {
    if (k % 2) {
      mat_mult_mat(bss, xss, tss, num_mod);
      copy_mat(tss, bss);
    }
    k /= 2;
    mat_mult_mat(xss, xss, tss, num_mod);
    copy_mat(tss, xss);
  }
}

long pow(long x, long k, long num_mod) {
  long ret = 1, p = x;
  while (k > 0) {
    if (k & 1) {
      ret = mod(ret * p, num_mod);
    }
    p = mod(p * p, num_mod);
    k /= 2;
  }
  return ret;
}

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  long L, A, B, M;
  scanf("%ld %ld %ld %ld", &L, &A, &B, &M);

  // calculate ten_pows[k]
  //     ten_pows[k] = 10^k
  vector<long> ten_pows(19, 0);
  ten_pows[0] = 1;
  for (long k = 0; k < 18; k++) {
    ten_pows[k + 1] = 10 * ten_pows[k];
  }

  // calculate as[k]
  //     as[k] : min(min_i {i | s_i >= 10^{k-1}}, L)
  vector<long> as;
  as.push_back(0);  // let as[0] = 0
  for (long k = 1; k <= 19; k++) {
    const long ten_pow_km1 = ten_pows[k - 1];
    long le = -1, ri = L;
    while (ri - le > 1) {
      const long m = (le + ri) / 2;
      if (A + B * m >= ten_pow_km1) {
        ri = m;
      } else {
        le = m;
      }
    }
    as.push_back(ri);
    // printf("k = %ld, as[k] = %ld\n", k, as[k]);
  }

  // solve
  const long N = 3;
  vector<vector<long>> xss(N, vector<long>(N, 0)),
      x_tmpss(N, vector<long>(N, 0));
  vector<long> vs(N, 0), v_tmps(N, 0);
  // initial vs = [t_1, s_1, 1]
  vs[0] = 0;
  vs[1] = A;
  vs[2] = 1;
  for (long k = 1; k < 19; k++) {
    // input X_k
    xss[0][0] = mod(ten_pows[k], M);
    xss[0][1] = 1;
    xss[0][2] = 0;
    xss[1][0] = 0;
    xss[1][1] = 1;
    xss[1][2] = B;
    xss[2][0] = 0;
    xss[2][1] = 0;
    xss[2][2] = 1;
    // calculate (X_k)^{as[k + 1] - as[k]}
    mat_pow(xss, as[k + 1] - as[k], x_tmpss, M);
    copy_mat(x_tmpss, xss);
    // update vs
    mat_mult_vec(xss, vs, v_tmps, M);
    copy_vec(v_tmps, vs);
  }
  printf("%ld\n", vs[0]);

  return 0;
}


Measured memory_bytes: 256