#include "bits/stdc++.h"

using ll = long long;

using namespace std;
#define int ll

// 0 -> a-1
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
// a -> b-1
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
// a-1 -> 0
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
// a-1 -> b
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
// next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
(v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v)                                                              \
	sort(all(v));                                                              \
	(v).erase(unique(all(v)), v.end())
#define CIN(type, x)                                                           \
	type x;                                                                    \
	cin >> x
#define YES(f)                                                                 \
	if ((f)) {                                                                 \
		cout << "YES" << endl;                                                 \
	} else {                                                                   \
		cout << "NO" << endl;                                                  \
	}
#define Yes(f)                                                                 \
	if ((f)) {                                                                 \
		cout << "Yes" << endl;                                                 \
	} else {                                                                   \
		cout << "No" << endl;                                                  \
	}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
// b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
// c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)
#define RS resize
#define CINV(v, N)                                                             \
	do {                                                                       \
		v.RS(N);                                                               \
		rep (i, N)                                                             \
			cin >> v[i];                                                       \
	} while (0);

#define RCINV(v, N)                                                            \
	do {                                                                       \
		v.RS(N);                                                               \
		rrep (i, N)                                                            \
			cin >> v[i];                                                       \
	} while (0);
#define MOD 1000000007

template <class T> inline T GET()
{
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

template <class T, char d = '\n'> struct Vector
{
	vector<T> v;
	Vector(int sz) : v(sz) {}
	Vector(int sz, T t) : v(sz, t) {}
	Vector() : v(0) {}
	Vector(vector<T> t) : v(t) {}
	inline auto begin() { return v.begin(); }
	inline auto end() { return v.end(); }
	inline auto rbegin() { return v.rbegin(); }
	inline auto rend() { return v.rend(); }
	inline int size() { return v.size(); }
	inline auto resize(int sz) { v.resize(sz); }
	inline auto resize(int sz, T t) { v.resize(sz, t); }
	inline auto empty() { v.empty(); }
	inline auto reserve(int sz) { v.reserve(sz); }
	inline auto push_back(T t) { v.push_back(t); }
	inline auto pop_back() { v.pop_back(); }
	inline auto assign(int sz, const T &t) { v.assign(sz, t); }
	inline auto &front() { return v.front(); }
	inline auto &back() { return v.back(); }
	inline auto insert(const typename vector<T>::iterator p, const T &t)
	{
		v.insert(p, t);
	}
	inline auto insert(const typename vector<T>::iterator p,
					   typename vector<T>::iterator f,
					   typename vector<T>::iterator l)
	{
		v.insert(p, f, l);
	}

	inline auto erase(const typename vector<T>::iterator p) { v.erase(p); }
	inline auto erase(const typename vector<T>::iterator f,
					  const typename vector<T>::iterator s)
	{
		v.erase(f, s);
	}
	inline auto emplace_back(T &t) { v.emplace_back(t); }
	inline auto swap(Vector<T> &f) { v.swap(f.v); }
	inline auto clear() { v.clear(); }
	inline auto &operator[](size_t pos) { return v[pos]; }
	inline auto operator<(const Vector &a) { return v < a.v; }
	inline auto operator>(const Vector &a) { return a < (*this); }
	inline auto operator>=(const Vector &a) { return !((*this) < a); }
	inline auto operator<=(const Vector &a) { return !(a < (*this)); }
	inline auto operator==(const Vector &a)
	{
		return !(a < (*this)) && !((*this) < a);
	}

	inline friend istream &operator>>(istream &lhs, Vector &rhs)
	{
		for (auto &x : rhs) lhs >> x;
		return lhs;
	}
	inline friend ostream &operator<<(ostream &lhs, Vector &rhs)
	{
		for (int i = 0; i + 1 < rhs.size(); i++) lhs << rhs[i] << d;
		if (rhs.size()) lhs << rhs.back();
		return lhs;
	}
	inline auto make_accumulate_sum(T init)
	{
		Vector<T> res;
		res.push_back(init);
		for (auto x : v) {
			auto y = res.back();
			res.push_back(y + x);
		}
		return res;
	}
};


int L, A, B, M;

int logpow(int x, long long p)
{
	x %= M;
	if (p == 0) {
		return 1;
	}
	if (p % 2) {
		return x % M * logpow(x, p-1) % M;
	}
	int t = logpow(x % M, p/2);
	return t * t % M;
}


template <class T>
struct Matrix
{
	int row;
	int column;
	vector<vector<T>> v;
	vector<T> &operator[](int i) { return (v[i]); }
	Matrix(int i, int j)
	{
		init(i, j);
	}
	Matrix()
	{
		init(0, 0);
	}
	void init(int i, int j)
	{
		row = i;
		column = j;
		v.resize(i, vector<T>(j, 0));
	}
	Matrix(const Matrix &cp)
	{
		row = cp.row;
		column = cp.column;
		v = cp.v;
	}
	~Matrix()
	{
	}
	Matrix operator=(const Matrix &a)
	{
		row = a.row;
		column = a.column;
		v = a.v;
		return (*this);
	}
 
	Matrix operator+(const Matrix &a)
	{
		Matrix r(row, column);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < column; j++)
			{
				r.v[i][j] = v[i][j] + a.v[i][j];
			}
		}
		return (r);
	}
 
	Matrix operator-(const Matrix &a)
	{
		Matrix r(row, column);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < column; j++)
			{
				r.v[i][j] = v[i][j] - a.v[i][j];
			}
		}
		return (r);
	}
	Matrix operator*(const Matrix &a)
	{
		Matrix r(row, a.column);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < a.column; j++)
			{
				for (int k = 0; k < column; k++)
				{
					r.v[i][j] += (v[i][k] % M) * (a.v[k][j] % M) % M;
					r.v[i][j] %= M;
				}
			}
		}
		return (r);
	}
	Matrix operator*(const int b)
	{
		Matrix r(row, column);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < column; j++)
			{
				r.v[i][j] = b * v[i][j];
			}
		}
		return (r);
	}
	Matrix operator+(const int b)
	{
		Matrix r(row, column);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < column; j++)
			{
				r.v[i][j] = b + v[i][j];
			}
		}
		return (r);
	}
	Matrix operator-(const int b)
	{
		Matrix r(row, column);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < column; j++)
			{
				r.v[i][j] = v[i][j] - b;
			}
		}
		return (r);
	}
	void unit_matrix()
	{
		int n = row;
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				v[i][j] = 0;
				if (i == j)
					v[i][j] = 1;
			}
		}
	}
	Matrix<T> accumu_sum()
	{
		Matrix<T> r(this->row+1, this->column+1);
		for (int i = 1; i <= this->row; i++)
		{
			for (int j = 1; j <= this->column; j++)
			{
				r[i][j] = this->v[i-1][j-1] + r[i-1][j] + r[i][j-1] - r[i-1][j-1];
			}
		}
		return (r);
	}
	T get_sum_accumu(int r1, int c1, int r2, int c2) //半開区間で指定
	{
		return v[r2][c2] + v[r1][c1] - v[r2][c1] - v[r1][c2];
	}
 
	Matrix transposed()
	{
		Matrix t(column, row);
		for (int i = 0; i < row; i++)
		{
			for (int j = 0; j < column; j++)
			{
				t[j][i] = v[i][j];
			}
		}
		return (t);
	}
	friend ostream &operator<<(ostream &lhs, const Matrix<T> &rhs)
	{
		for (int i = 0; i < rhs.row; i++)
		{
			for (int j = 0; j < rhs.column - 1; j++)
			{
				lhs << rhs.v[i][j] << " ";
			}
			lhs << rhs.v[i][rhs.column - 1];
			if (i != rhs.row-1) cout << endl;
		}
		return lhs;
	}
	friend istream &operator>>(istream &lhs, Matrix<T> &rhs)
	{
		for (int i = 0; i < rhs.row; i++)
		{
			for (int j = 0; j < rhs.column; j++)
			{
				lhs >> rhs.v[i][j];
			}
		}
		return lhs;
	}
};

Matrix<int> logpowM(Matrix<int> x, long long p)
{
	if (p == 0) {
		Matrix<int> t = x;
		t.unit_matrix();
		return t;
	}
	if (p % 2) {
		return x * logpowM(x, p - 1);
	}
	auto t = logpowM(x, p/2);
	return t * t;
}


void init()
{
	cin >> L >> A >> B >> M;
	int D = 0;
	int G = 1;
	int res = 0;
	while (L) {
		{
			D = 0;
			G = 1;
			int t = A;
			while (t) {
				D++;
				t /= 10;
				G *= 10;
			}
		}
		int k;
		if (D < 18) {
			k = (G - A + B - 1) / B - 1;
		} else {
			k = L - 1;
		}
		assert(G >= 0);
		k = min(k, L-1);
		int k10 = logpow(10, D);
		Matrix<int> LL(3, 3);
		LL[0][0] = k10 % M;
		LL[0][1] = 1;
		LL[1][1] = 1;
		LL[1][2] = B % M;
		LL[2][2] = 1;
		Matrix<int> RR(3, 1);
		RR[0][0] = res;
		RR[1][0] = A % M;
		RR[2][0] = 1;
		auto t = logpowM(LL, k + 1);
		auto u = t * RR;
		res = u[0][0];
		L -= k + 1;
		A += (k + 1) * B;
	}
	cout << res << endl;
}

void solve()
{
}


Measured memory_bytes: 256