#include <bits/stdc++.h>

int64_t L, A, B, mod;

////////////
// 行列型 //
///////////

// 加算、減算、乗算をもつM×N型行列
// M=Nで環をつくる
template<typename T = int64_t>
class Matrix {
private:
	using RowVector = std::vector<T>;

	std::vector<RowVector> container_;

public:
	const int M, N;

	Matrix(const int row_size, const int column_size)
		: M(row_size), N(column_size), container_(row_size, RowVector(column_size)){}
	// ムーブコンストラクタ
	Matrix(Matrix&& mat)
		: M(mat.M), N(mat.N), container_(std::move(mat.container_)){}
	// コピーコンストラクタ
	Matrix(Matrix& mat)
		: M(mat.M), N(mat.N), container_(mat.container_){}

	// 要素アクセス
	RowVector& operator[](const int r) { return container_[r]; }
	const RowVector& operator[](const int r) const { return container_[r]; }
	// イテレータ
	typename decltype(container_)::iterator begin(){ return container_.begin(); }
	typename decltype(container_)::iterator end(){ return container_.end(); }
	
	Matrix operator*(const Matrix& mat) const
	{
		Matrix ret(this->M, mat.N);
		for (int r_i{}; r_i < this->M; r_i++)
			for (int c_i{}; c_i < mat.N; c_i++)
				for (int l_i{}; l_i < this->N; l_i++)
					ret[r_i][c_i] = (ret[r_i][c_i] + (*this)[r_i][l_i] * mat[l_i][c_i]) % mod;
		return std::move(ret);
	}
	std::vector<T> operator*(const std::vector<T>& vec) const
	{
		std::vector<T> ret(M);
		for (int r_i{}; r_i < M; r_i++)
			for (int c_i{}; c_i < N; c_i++)
				ret[r_i] = (ret[r_i] + (*this)[r_i][c_i] * vec[c_i]) % mod;
		return std::move(ret);
	}

	// 累乗
	Matrix operator^(const int64_t index)
	{
		Matrix ret(getOne()), pow(*this);
		for (int64_t i{index}; i > 0; i >>= 1)
		{
			if (i & 1)
				ret *= pow;
			pow *= pow;
		}
		return std::move(ret);
	}

	// 代入演算子
	Matrix& operator=(const Matrix& mat)
	{
		this->container_ = mat.container_;
		return *this;
	}
	Matrix& operator*=(const Matrix& mat)
	{
		*this = *this * mat;
		return *this;
	}
	
	constexpr Matrix getOne() const
	{
		Matrix ret(M, N);
		for (int i{}; i < N; i++)
			ret[i][i] = 1ll;
		return std::move(ret);
	}
};

int main()
{
	scanf("%lld%lld%lld%lld", &L, &A, &B, &mod);
	std::vector<int64_t> digit(19, -1);
	int64_t ten_pow{1};
	for (int i{1}; ; i++)
	{
		ten_pow *= 10;
		if (A >= ten_pow) continue;
		digit[i] = (ten_pow - 1 - A) / B;
		if (digit[i] >= L - 1)
		{
			digit[i] = L - 1;
			break;
		}
	}

	A %= mod;
	B %= mod;
	std::vector<int64_t> sum(19);
	ten_pow = 1;
	for (int i{1}; digit[i - 1] != L - 1; i++)
	{
		ten_pow = ten_pow * 10 % mod;
		if (digit[i] < 0 || digit[i] == digit[i - 1]) continue;
		int64_t num{digit[i] - digit[i - 1]};

		Matrix<> aMat(2, 2);
		aMat[0][0] = ten_pow;
		aMat[0][1] = aMat[1][1] = 1;
		std::vector<int64_t> beginA{0, 1};
		sum[i] = ((aMat ^ num) * beginA)[0] * ((A + (digit[i - 1] + 1) % mod * B % mod) % mod) % mod;
		
		Matrix<> bMat(4, 4);
		bMat[0][0] = ten_pow;
		bMat[0][1] = bMat[1][1] = bMat[2][0] = bMat[3][1] = bMat[2][2] = bMat[3][3] = 1;
		Matrix<> beginB(4, 2);
		beginB[0][0] = beginB[1][1] = 1;
		sum[i] = (sum[i] + B % mod * ((bMat ^ num) * beginB * beginA)[2] % mod) % mod;
	}
	std::vector<int64_t> shift(19, 1);
	for (int i{17}; i > 0; i--)
	{
		if (digit[i + 1] < 0) continue;
		int64_t tmp{1};
		ten_pow = 10;
		for (int64_t j{(digit[i + 1] - digit[i])}; j > 0; j >>= 1, ten_pow = ten_pow * ten_pow % mod)
			if (j & 1)
				tmp = tmp * ten_pow % mod;
		shift[i] = shift[i + 1];
		for (int64_t j{i + 1}; j > 0; j >>= 1, tmp = tmp * tmp % mod)
			if (j & 1)
				shift[i] = shift[i] * tmp % mod;
		sum[i] = sum[i] * shift[i] % mod;
	}
	int64_t ans{};
	for (int i{1}; i <= 18; i++)
	{
		if (digit[i] < 0 || digit[i] == digit[i - 1]) continue;
		ans = (ans + sum[i]) % mod;
	}
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 384