#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

ll l, A, B;

using vec = vector<ll>;
using mat = vector<vector<ll> >;
int m;
vec matmul(vec &dp, mat &mt) {
  vec ret(m, 0);
  rep(i, m) rep(j, m) {
    add(ret[i], mt[i][j] % mod * (dp[j] % mod) % mod);
  }
  return ret;
}
mat update(mat &mt) {
  mat ret(m, vec(m, 0));
  rep(i, m) rep(j, m) rep(k, m) {
    add(ret[i][j], mt[i][k] % mod * (mt[k][j] % mod) % mod);
  }
  return ret;
}
// mt[0] : 1 "列"目
void matpow(vec &dp, mat &mt, ll k) {
  m = sz(dp);
  while (k) {
    if (k & 1) dp = matmul(dp, mt);
    mt = update(mt);
    k >>= 1;
  }
}

int f(ll x) {
  int c = 0;
  while (x) {
    x /= 10;
    c++;
  }
  return c;
}

template<typename T>
bool check(T x, int keta) {
  ll y = B * x;
  if (x != 0 && y / x != B) return 0; // debuged
  y += A;
  if (f(y) <= keta) return 1;
  return 0;
}

template<typename T>
ll binary_search(T ok, T ng, int keta) { // debuged, int to ll
  while (abs(ng - ok) > 1) {
    T mid = (ng + ok) / 2;
    (check(mid, keta) ? ok : ng) = mid;
  }
  return ok;
}

// pdf editorial
void solve() {
  int M;
  cin >> l >> A >> B >> M;
  mod = M;
  vec v{0, A, 1};
  // cout << v << endl;

  // 要素数が二分探索でうまくいかない
  // とりあえず過去のコードで行列累乗以外は
  ll last = A + B * (l - 1);
  ll ten = 1;
  rep3(d, 1, 19) {
    // cout << pow(10LL, d) << endl;
    mat mt{{pow(10LL, d), 1, 0}, {0, 1, B}, {0, 0, 1}};
    // cout << endl; rep(i, 3) cout << mt[i] << endl;
    ll L = binary_search(-1LL, l, d - 1);
    L++;
    if (f(A + B * L) != d) continue;
    ll R = binary_search(0LL, l, d);
    ll Cd = R - L + 1;
    // cout << d << " " << L << " " << R << " " << Cd << endl;
    matpow(v, mt, Cd);
    // cout << d << "  " << v << endl;
    if (R == l - 1) break;
  }
  cout << v[0] << endl;
}


Measured memory_bytes: 256