#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}

template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){
  Int i=0;
  o<<"[";
  for(T t:a)o<<(i++?", ":"")<<t;
  o<<"]";
  return o;}
//INSERT ABOVE HERE

class Integer{
public:
  string val;
  Integer():val("0"){}
  Integer(string num,bool reversed=0){if(!reversed)R(num); val = num;}
  Integer(Int num){val = to_string(num); R(val);}
  
  void R(string &a){reverse(a.begin(),a.end());}
  bool neg(const string &a)const{return a.back() == '-';}
  char& operator [] (Int i){assert(i<(Int)val.size());return val[i];}

  bool operator ==  (Integer b) {R(b.val); return *this == b.val;}
  bool operator ==  (string b) {R(b);return val == b;}
  template<class T> bool operator == (T b){return *this == Integer(b);}
  
  bool operator !=  (Integer b) {R(b.val); return *this != b.val;}
  bool operator !=  (string b) {R(b);return !(val == b);}
  template<class T> bool operator != (T b){return *this != Integer(b);}
  
  bool operator >=  (Integer b) {R(b.val); return *this >= b.val;}
  bool operator >=  (string b) {return !(*this < b);}
  template<class T> bool operator >= (T b){return *this >= Integer(b);}

  bool operator >   (Integer b) {R(b.val); return *this > b.val;}
  bool operator >   (string b) {return *this>=b && *this != b;}
  template<class T> bool operator > (T b){return *this > Integer(b);}

  bool operator <=  (Integer b) {R(b.val); return *this <= b.val;}
  bool operator <=  (string b) {return *this<b || *this == b;}
  template<class T> bool operator <= (T b){return *this <= Integer(b);}

  bool operator <   (Integer b) {R(b.val); return *this < b.val;}
  template<class T> bool operator < (T b){return *this < Integer(b);}
 
   bool operator <   (string b) {
    R(b);
    const string &a = val;
    if(neg(a) != neg(b)) return neg(a)? 1:0;
    if(a.size() != b.size()) return !neg(a)? (a.size()<b.size()):(a.size()>b.size());
    for(Int i=a.size()-1;i>=0;i--)if(a[i] != b[i]) return !neg(a)? a[i] < b[i]: a[i] > b[i];
    return 0;
  }
  
  Integer operator + (string b){
    R(b);
    string a = val;
    string fa = neg(a)? "-":"";
    string fb = neg(b)? "-":"";
    if(neg(a)) a.pop_back();
    if(neg(b)) b.pop_back();
    if(Integer(a,1) < Integer(b,1)) swap(a,b),swap(fa,fb);
    
    if(fa == fb){
      a += '0';
      for(Int i=0;i<(Int)a.size()-1;i++){
        if(i < (Int)b.size()) a[i] += b[i]-'0';
        a[i+1] += (a[i]-'0')/10;
        a[i] = (a[i]-'0')%10 + '0';
      }
      if(a.size() > 1 && a.back() == '0') a.pop_back();
      if((Int)a.size() > 1 && a.back() == '0') a.pop_back();
      if(a != "0") a += fa;
    }
    else {
      for(Int i=0;i<(Int)a.size();i++){
        if(i < (Int)b.size()) a[i] -= b[i]-'0';
        if(a[i]-'0' < 0) a[i]+=10, a[i+1]--; 
      }
      while((Int)a.size()>1 && a.back() == '0') a.pop_back();
      if(a != "0") a += fa;
    }
    return Integer(a,1);
  }

  Integer operator * (string b){
    R(b);
    vector<Int> res;
    string a = val;
    string fa = neg(a)? "-":"";
    string fb = neg(b)? "-":"";
    if(neg(a)) a.pop_back();
    if(neg(b)) b.pop_back();
    if(a.size() < b.size()) swap(a,b), swap(fa,fb);
    if(a == "0" || b == "0") return Integer("0");
    
    for(Int j=0;j<(Int)b.size();j++)
      for(Int i=0;i<(Int)a.size();i++){
        if(i+j >= (Int)res.size()) res.push_back(0);
        res[i+j] += (a[i]-'0') * (b[j]-'0');
      }
    for(Int i=0; i <(Int)res.size(); i++) {
      if(res[i]/10 == 0) continue;
      if(i + 1 >= (Int)res.size()) res.push_back(0);
      res[i+1] += res[i]/10, res[i]=res[i]%10;
    }
    string sres;
    for(Int i:res) sres += char(i + '0');
    if(fa != fb) sres += '-';
    return Integer(sres,1);
  }

  Integer div(string b,Int flg){
    assert(b != "0");
    string a = val;
    string fa = neg(a)? "-":"";
    string fb = b[0]=='-'? "-":"";
    if(neg(a)) a.pop_back();
    if(b[0]=='-') b.erase(b.begin());
    Integer mod("0");
    string d="0";
    for(Int i=(Int)a.size()-1;i>=0;i--){
      mod = mod * 10 + (a[i] - '0');
      while(mod >= b) mod -= b, d.back()+=1;
      if(i && d != "0") d += '0'; 
    }
    if(flg == 0 && d != "0" && (fa != fb)) d = "-" + d;
    if(flg == 1 && mod != "0" && (fa == "-")) mod *= -1;
    return flg==0? d:mod;
  }
  
  Integer operator + (Integer b){R(b.val); return *this + b.val;}
  template<class T> Integer operator + (T b){return *this + Integer(b);}
  
  Integer operator * (Integer b){R(b.val); return *this * b.val;}
  template<class T> Integer operator * (T b){return *this * Integer(b);}

  Integer operator - (string b){b = (b[0] == '-')? b.substr(1):"-" + b;return *this + b;}
  Integer operator - (Integer b){R(b.val); return *this - b.val;} 
  template<class T> Integer operator - (T b){return *this - Integer(b);}
  
  Integer operator / (string b){return div(b,0);}
  Integer operator / (Integer b){R(b.val);return div(b.val,0);}
  template<class T> Integer operator / (T b){return *this / Integer(b);}
  
  Integer operator % (string b){return div(b,1);}
  Integer operator % (Integer b){R(b.val);return div(b.val,1);}
  template<class T> Integer operator % (T b){return *this % Integer(b);}
  
  Integer operator += (Integer b){return *this = *this+b;}
  Integer operator += (string b){return *this = *this+b;}
  template<class T> Integer operator += (T b){return *this += Integer(b);}
  
  Integer operator -= (Integer b){return *this = *this-b;}
  Integer operator -= (string b){return *this = *this-b;}
  template<class T> Integer operator -= (T b){return *this -= Integer(b);}
  
  Integer operator *= (Integer b){return *this = *this*b;}
  Integer operator *= (string b){return *this = *this*b;}
  template<class T> Integer operator *= (T b){return *this *= Integer(b);}
  
  Integer operator /= (string b){return *this = *this/b;}
  Integer operator /= (Integer b){return *this = *this/b;}
  template<class T> Integer operator /= (T b){return *this /= Integer(b);}
  
  Integer operator %= (string b){return *this = *this % b;}
  Integer operator %= (Integer b){return *this=*this%b;}
  template<class T> Integer operator %= (T b){return *this %= Integer(b);}
  
  Integer operator ++(){return *this += 1;}
  Integer operator --(){return *this -= 1;}

#ifdef Int
#undef Int
#define eraseIntegerDefine
#endif
  Integer operator ++(int){
    Integer tmp = *this;
    *this += 1;
    return tmp;
  }
  
  Integer operator --(int){
    Integer tmp = *this;
    *this -= 1;
    return tmp;
  }
#ifdef eraseIntegerDefine
#define Int long long
#endif

  friend ostream& operator << (ostream& os,const Integer a){
    for(Int i=(Int)a.val.size()-1;i>=0;i--) os<<a.val[i];
    return os;
  }

  friend istream& operator >> (istream& is,Integer &a){
    string num;
    is>>num;
    a = Integer(num);
    return is;
  }
  friend string to_string(Integer a){reverse(a.val.begin(),a.val.end());return a.val;}
};


Int mod;
typedef vector<Int> vec;
typedef vector<vec> mat;

/*掛け算*/
mat mult(const mat &A,const mat &B){
  assert(A[0].size() == B.size());
  Int n = A.size(),m = B.size(),l = B[0].size();
  mat C(A.size(),vec(l,0));

  for(Int i=0;i<n;i++)
    for(Int j=0;j<l;j++)
      for(Int k=0;k<m;k++) {
	C[i][j] += (A[i][k]*B[k][j])%mod;
	C[i][j] %= mod;
      }  
  return C;
}

mat pow(mat A,Integer y){
  mat res(A.size(), vec(A.size()));
  for(Int i=0;i<(Int)A.size();i++) res[i][i] = 1;
  while(y != 0){
    if(y%2 == 1) res = mult(res, A);
    A = mult(A, A);
    y /= 2;
  }
  return res;
}


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  Int L,tmpA, tmpB, M;
  cin>>L>>tmpA>>tmpB>>M;
  Integer A = tmpA;
  Integer B = tmpB;
  mod = M;

  Integer l = 0;
  Integer Limit = 1;
  Int limit = 1;
  
  mat Q = {{0}, {tmpA%mod}, {tmpB%mod}};
  
  while(l < L){
    Limit = Limit * 10;
    limit = limit * 10 % mod;
    // A + B * r < limit
    //         r < (limit - A) / B;
    Integer num = (Limit - A - 1) / B + 1;
    if(A >= Limit || num <= 0) continue;
    Integer r = l + num;
    if(r > L) r = L;
    
    mat P = {
      {limit, 1, 0},
      {0, 1, 1},
      {0, 0, 1}
    };

    P = pow(P, r - l);
    Q = mult(P, Q);
    //pr(l, r, Limit, P, Q, A);
    A = A + B * (r - l);
    l = r;
  }
  

  Int ans = Q[0][0];
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256