/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxd = 25;

/*
1 1 0 cur
0 1 0 delta
1 0 p sum
*/

ll l, a, b, m;
vector<pll> pos;

class Matrix{
private:
public:
	int w, h;
	int arr[5][5];
	Matrix(int _w, int _h): w(_w), h(_h){
		FOR(i, 0, w) FOR(j, 0, h) arr[i][j] = 0;
		return;
	}
	int* operator [](const int &i){return arr[i];}
	void print(){
		printf("w = %d h = %d\n", w, h);
		FOR(i, 0, w){
			FOR(j, 0, h) printf("%lld ", arr[i][j]);
			puts("");
		}
		puts("");
		return;
	}
};

Matrix operator * (Matrix A, Matrix B){
	Matrix ret(A.w, B.h);
	FOR(i, 0, ret.w){
		FOR(j, 0, ret.h){
			FOR(k, 0, A.h) (ret[i][j] += (A[i][k] % m * B[k][j] % m) % m) %= m;
		}
	}
	return ret;
}

Matrix operator ^ (Matrix A, ll y){
	if(y == 1)
		return A;
	Matrix ret = A;
	for(--y; y; y >>= 1){
		if(y & 1)
			ret = ret * A;
		A = A * A;
	}
	return ret;
}

ll getTerm(ll fir, ll ind, ll del){/*printf("%lld %lld %lld %lld\n", fir, ind, del, fir + (ind - 1) * del); */return fir + (ind - 1) * del;}
int count(ll x){int ret; for(ret = 0; x; x /= 10) ++ret; return ret;}

ll getMinIndex(int cnt){
	ll lb, rb;
	for(lb = 0, rb = l + 1; lb + 1 < rb;){
		ll md = lb + rb >> 1;
		ll cur = getTerm(a, md, b);
		if(count(cur) >= cnt)
			rb = md;
		else
			lb = md;
	}
	return rb;
}

int main(){
	scanf("%lld%lld%lld%lld", &l, &a, &b, &m);
	FOR(i, 1, 20){
		ll p = getMinIndex(i);
		if(p > l)
			break;
		if(count(getTerm(a, p, b)) == i)
			pos.PB(MP(p, i));
	}
	pos.PB(MP(l + 1, 0));
	Matrix A = Matrix(3, 1), B = Matrix(3, 3);
	ll ans = 0;
	FOR(i, 0, pos.size() - 1){
		//printf("pos = (%lld %lld)\n", pos[i].fst, pos[i].snd);
		ll curBase = 1;
		FOR(j, 0, pos[i].snd) (curBase *= 10) %= m;
		A[0][0] = getTerm(a, pos[i].fst, b) % m, A[1][0] = b % m, A[2][0] = ans;
		B[0][0] = 1, B[1][1] = 1, B[0][1] = 1, B[2][0] = 1, B[2][2] = curBase;
		//puts("A");
		//A.print();
		//puts("B");
		//B.print();
		Matrix P = (B ^ (pos[i + 1].fst - pos[i].fst)) * A;
		//puts("P");
		//P.print();
		ans = P[2][0];
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 256