#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;

matrix mult(matrix a, matrix b, int m) {
  matrix c;
  for(int i = 0; i < a.size(); i++) {
    c.push_back({});
    for(int j = 0; j < b[0].size(); j++) {
      c[i].push_back(0);
      for(int k = 0; k < b.size(); k++) {
        c[i][j] += a[i][k] * b[k][j];
        c[i][j] %= m;
      }
    }
  }
  return c;
}

matrix pow(matrix b, ll e, int m) {
  matrix r;
  for(int i = 0; i < b.size(); i++) {
    r.push_back({});
    for(int j = 0; j < b.size(); j++) {
      r[i].push_back(i == j);
    }
  }
  while(e) {
    if(e%2) {
      r = mult(r, b, m);
    }
    e /= 2;
    if(e) {
      b = mult(b, b, m);
    }
  }
  return r;
}

void solve(ll start, ll diff, ll numTerms, ll m) {
  ll len = 1;
  ll currCap = 9;
  matrix curr;
  curr.push_back({0});
  curr.push_back({start%m});
  curr.push_back({1});
  while(numTerms > 0) {
    /*
    (x, start, 1) -> (10**len*x + start, start + diff, 1)
    */
    len *= 10;
    len %= m;
    for(int d = 60; d >= 0; d--) {
      if((1LL << d) > numTerms) continue;
      ll lastTerm = start + (-1 + (1LL << d)) * diff;
      if(lastTerm <= currCap) {
        numTerms -= 1LL << d;
        matrix b = {
          {len, 1, 0},
          {0, 1, diff%m},
          {0, 0, 1}
        };
        curr = mult(pow(b, 1LL << d, m), curr, m);
        start += (1LL << d) * diff;
      }
    }
    currCap = 10 * currCap + 9;
  }
  cout << curr[0][0] << "\n";
}

void solve() {
  ll a, b, n, m;
  cin >> n >> a >> b >> m;
  solve(a, b, n, m);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}
