#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


// Modint
ll mod = 1e18;
struct Mint {
	ll val;

	Mint() { val = 0; }
	Mint(ll a) { val = a; verify_value(); }

	void verify_value() {
		if (val >= mod) val %= mod;
		if (val < 0) val %= mod, val += mod;
	}

	Mint pow(ll p) const {
		Mint cur = Mint(val), ret = 1;
		while (p > 0) {
			if (p & 1) ret *= cur;
			cur *= cur;
			p >>= 1LL;
		}
		return ret;
	}
	Mint inv() const {
		if (val == 0) cerr << "WARNING: inv() is called with 0." << endl;
		return pow(mod - 2);
	}

	Mint operator+() const { return *this; }
	Mint operator-() const { return Mint(mod - val); }

	Mint operator+=(const Mint &a) {
		val += a.val;
		if (val >= mod) val -= mod;
		return Mint(val);
	}
	Mint operator*=(const Mint &a) {
		val *= a.val;
		if (val >= mod) val %= mod;
		return Mint(val);
	}
	Mint operator-=(const Mint &a) { return *this += -a; }
	Mint operator/=(const Mint &a) { return *this *= a.inv(); }

	Mint operator++() { return *this += Mint(1); }
	Mint operator--() { return *this -= Mint(1); }
	Mint operator++(int) {
		Mint ret = *this;
		++(*this);
		return ret;
	}
	Mint operator--(int) {
		Mint ret = *this;
		--(*this);
		return ret;
	}

	operator ll() const { return val; }
};

Mint operator+(const Mint &a, const Mint &b) {
	ll ret = a.val + b.val;
	if (ret >= mod) ret -= mod;
	return Mint(ret);
}
Mint operator*(const Mint &a, const Mint &b) {
	ll ret = a.val * b.val;
	if (ret >= mod) ret %= mod;
	return Mint(ret);
}
Mint operator-(const Mint &a, const Mint &b) { return a + (-b); }
Mint operator/(const Mint &a, const Mint &b) { return a * b.inv(); }

ostream &operator<<(ostream &out, const Mint &a) { return out << a.val; }
istream &operator>>(istream &in, Mint &a) {
	in >> a.val;
	a.verify_value();
	return in;
}

Mint pow(Mint a, int b) {
	return a.pow(b);
}

// Matrix power
template<typename T>
class Matrix {
	vector<vector<T>> dat;
public:
	Matrix(int n, int m) { dat = vector<vector<T>>(n, vector<T>(m)); }
	Matrix(int n, int m, T init_val) { dat = vector<vector<T>>(n, vector<T>(m, init_val)); }
	Matrix(int n) : Matrix(n, n) {}
	Matrix(int n, T init_val) : Matrix(n, n, init_val) {}
	vector<T> &operator[](size_t idx) { return dat[idx]; }
	const vector<T> &operator[](size_t idx) const { return dat[idx]; }
	size_t size() const { return dat.size(); }
};
template<typename T>
ostream &operator<<(ostream &out, const Matrix<T> &a) {
	for (int i = 0; i < (int)a.size(); i++) {
		for (int j = 0; j < (int)a[i].size(); j++) {
			out << a[i][j] << " \n"[j == (int)a[i].size() - 1];
		}
	}
	return out;
}

template<typename T>
Matrix<T> matmul(const Matrix<T> &a, const Matrix<T> &b) {
	int n = (int)a.size();
	int m = (int)b[0].size();
	int r = (int)b.size();
	assert(a[0].size() == r);
	Matrix<T> ret(n, m);
	for (int i = 0; i < n; i++) {
		for (int k = 0; k < r; k++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	return ret;
}

template<typename T>
Matrix<T> matpow(Matrix<T> a, ll p) {
	int n = (int)a.size();
	Matrix<T> ret(n);
	for (int i = 0; i < n; i++) ret[i][i] = 1;
	while (p > 0) {
		if (p & 1) ret = matmul(ret, a);
		a = matmul(a, a);
		p >>= 1LL;
	}
	return ret;
}

int main() {
	ll L, A, B; cin >> L >> A >> B >> mod;
	Matrix<Mint> x(3, 1);
	x[0][0] = A; x[1][0] = A; x[2][0] = B;
	Matrix<Mint> m(3);
	auto cnt = [&](ll t) {
		return max(1LL, min((t - 1 - A) / B + 1, L));
	};
	ll t = 1;
	for (int d = 1; d <= 18; d++) {
		t *= 10;
		ll p = cnt(t) - cnt(t/10);
		m[0][0] = t; m[0][1] = m[0][2] = 1;
		m[1][1] = m[1][2] = 1;
		m[2][2] = 1;
		m = matpow(m, p);
		x = matmul(m, x);
	}
	cout << x[0][0] << endl;
	return 0;
}


Measured memory_bytes: 256