#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

ll P;
//-------------------------------------------------------------------
// matrix<集合> (集合, 加法における単位元, 加算, 乗算)
template<typename T>
struct matrix{
  function<T(T, T)> f, g;
  vector<vector<T>> mat;
  T unit;

  matrix(vector<vector<T>> v, T UNIT, function<T(T, T)> add_func,
  function<T(T, T)> multi_func):f(add_func), g(multi_func), unit(UNIT){
    mat = v;
  }

  matrix<T> t(){
    vector<vector<T>> ret(mat[0].size(), vector<T>(mat.size()));
    re(i, mat[0].size()) re(j, mat.size()) ret[i][j] = mat[j][i];
    return matrix<T>(ret, f, g);
  }

  matrix<T> operator * (matrix<T> B){
    vector<vector<T>> ret(mat.size(), vector<T>(B.mat[0].size(), unit));
    if(mat[0].size()!=B.mat.size()){
      std::cout << "matrix operator " << "*" << " error" << '\n';
      return matrix<T>(ret, unit, f, g);
    }
    re(i, mat.size()){
      re(j, B.mat[0].size()){
        re(k, mat[0].size()){
          ret[i][j] = f(ret[i][j], g(mat[i][k], B.mat[k][j]));
        }
      }
    }
    return matrix<T>(ret, unit, f, g);
  }

  matrix<T> operator * (ll num){
    vector<vector<T>> ret = mat;
    re(i, mat.size()) re(j, mat[0].size()) ret[i][j] *= num;
    return matrix<T>(ret, unit, f, g);
  }

  matrix<T> operator + (matrix<T> B){
    vector<vector<T>> ret = mat;
    if(mat.size()!=B.mat.size()||mat[0].size()!=B.mat[0].size()){
      std::cout << "matrix operator " << "+" << " error" << '\n';
      return matrix<T>(ret, unit, f, g);
    }
    re(i, mat.size()) re(j, mat[0].size()) ret[i][j] = f(mat[i][j], B.mat[i][j]);
    return matrix<T>(ret, unit, f, g);
  }

  matrix<T> operator ^ (ll num){
    matrix<T> ret(vector<vector<T>> (0, vector<T>(0)), unit, f, g);
    if(mat.size()!=mat[0].size()){
      std::cout << "matrix operator " << "^" << " error" << '\n';
      return ret;
    }
    matrix<T> tmp(mat, unit, f, g);
    bool flag = false;
    while(num>0){
      if(num%2){
        if(flag) ret = ret * tmp;
        else ret.mat = tmp.mat, flag = true;
      }
      num/=2, tmp = tmp * tmp;
    }
    return ret;
  }
  vector<T> & operator [](int n){
    return mat[n];
  }
};
ll ad(ll a, ll b){return (a+b)%P;}
ll ml(ll a, ll b){return (a*b)%P;}

//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  ll l, A, B;std::cin >> l >> A >> B >> P;
  vll ten(19, 1);
  for(ll i=1;i<=18;i++) ten[i] = ten[i-1]*10;
  matrix<ll> base_B(vvl{vll{0}, vll{B%P}, vll{1}}, 0, ad, ml);
  matrix<ll> base_A(vvl{vll{A%P}, vll{1}}, 0, ad, ml);

  ll pre = 0;
  for(ll keta=1;keta<=18;keta++){
    matrix<ll> keta_B(
      vvl{
        vll{ten[keta]%P, 1, 0},
        vll{0, 1, B%P},
        vll{0, 0, 1}
      }, 0, ad, ml);
    matrix<ll> keta_A(vvl{vll{ten[keta]%P, A%P}, vll{0, 1}}, 0, ad, ml);
    ll ed = min((ten[keta]-1-A)/B, l-1);
    ll times = ed - pre;
    pre = max(pre, ed);
    if(times<=0) continue;
    base_B = (keta_B^times)*base_B;
    base_A = (keta_A^times)*base_A;
  }
  std::cout << (base_B[0][0] + base_A[0][0])%P << '\n';
  return 0;
}


Measured memory_bytes: 888