#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e10;

int64_t powd(int64_t a,int64_t b){//a^bを求める
	if(b==0){
		return 1;
	}else{
		int64_t temp = powd(a,b/2);
		temp = temp * temp;
		if(b%2==1){
			temp = temp * a;
		}
		return temp;
	}
}


template<class T> class matrix2d{
public:
	matrix2d(ll row,ll col):row(row),col(col){
		value.resize(row);
		for(ll i1=0;i1<row;i1++){
			value[i1].resize(col);
		}
	}
	matrix2d(ll row,ll col,T initial):row(row),col(col){
		value.resize(row);
		for(ll i1=0;i1<row;i1++){
			value[i1].resize(col,initial);
		}

	}
	template<class UnaryOperation>
	matrix2d& elementwise(UnaryOperation op){
		for(ll i1=0;i1<row;i1++){
			transform(value[i1].begin(),value[i1].end(),value[i1].begin(),op);
		}
		return *this;
	}
	template<class BinaryOperation>
	matrix2d& elementwise(const matrix2d& c,BinaryOperation op){
		for(ll i1=0;i1<row;i1++){
			transform(value[i1].begin(),value[i1].end(),c.value[i1].begin(),value[i1].begin(),op);
		}
		return *this;
	}

	//add
	matrix2d operator+(const T& c) const{
		matrix2d copy = matrix2d(*this);
		copy+=c;
		return copy;
	}
	matrix2d& operator+=(const T& c){
		auto func1 = std::bind(std::plus<T>(),std::placeholders::_1,c);
		elementwise(func1);
		return *this;
	}
	matrix2d operator+(const matrix2d& c) const{
		matrix2d copy=matrix2d(*this);
		copy+=c;
		return copy;

	}
	matrix2d& operator+=(const matrix2d& c){
		assert(col == c.col&&row==c.row);
		elementwise(c,std::plus<T>());
		return *this;
	}
	//multiply
	matrix2d operator*(const T& c) const{
		matrix2d copy = matrix2d(*this);
		copy*=c;
		return copy;
	}
	matrix2d& operator*=(const T& c){
		assert(col == c.col&&row==c.row);
		auto func1 = std::bind(std::multiplies<T>(),std::placeholders::_1,c);
		elementwise(func1);
		return *this;
	}
	matrix2d operator*(const matrix2d& c) const{
		matrix2d copy=new matrix2d(*this);
		copy*=c;
		return copy;
	}
	matrix2d& operator*=(const matrix2d& c){
		assert(col == c.col&&row==c.row);
		elementwise(c,std::multiplies<T>());
		return *this;
	}

	//subtract
	template<class U>
	matrix2d& operator-(const U &c){
		matrix2d copy=new matrix2d(*this);
		copy-=c;
		return copy;
	}
	template<class U>
	matrix2d& operator-=(const U &c){
		operator+=(c*-1);
	}
	//divide
	matrix2d operator/(const T& c) const{
		matrix2d copy = matrix2d(*this);
		copy/=c;
		return copy;
	}
	matrix2d& operator/=(const T& c){
		auto func1 = std::bind(std::divides<T>(),std::placeholders::_1,c);
		elementwise(func1);
		return *this;
	}
	matrix2d operator/(const matrix2d& c) const{
		matrix2d copy=new matrix2d(*this);
		copy/=c;
		return copy;
	}
	matrix2d& operator/=(const matrix2d& c){
		assert(col == c.col&&row==c.row);
		elementwise(c,std::divides<T>());
		return *this;
	}
	matrix2d operator%(const T &c) const{
		matrix2d copy = matrix2d(*this);
		copy%=c;
		return copy;
	}
	matrix2d& operator%=(const T& c){
		auto func1 = std::bind(std::modulus<T>(),std::placeholders::_1,c);
		elementwise(func1);
		return *this;
	}

	matrix2d dot(const matrix2d &c){
		assert(col==c.row);
		matrix2d retval(row,c.col);
		for(ll i1=0;i1<row;i1++){
			for(ll i2=0;i2<c.col;i2++){
				T sum=0;
				for(ll i3=0;i3<col;i3++){
					sum += (value[i1][i3]*c.value[i3][i2]);
				}
				retval(i1,i2)=sum;
			}
		}
		return retval;
	}

	matrix2d pow(ll b){//(この行列)^bを求める
		assert(row==col);
		if(b==0){
			//return I
			matrix2d<T> id(row,col,0);
			for(ll i1=0;i1<row;i1++){
				id(i1,i1)=1;
			}
			return id;
		}else{
			matrix2d<T> temp = pow(b/2);
			temp = temp.dot(temp);
			if(b%2==1){
				temp=temp.dot(*this);
			}
			return temp;
		}
	}
	matrix2d powmod(ll b,ll m){//(この行列)^b mod mを求める
		assert(row==col);
		if(b==0){
			//return I
			matrix2d<T> id(row,col,0);
			for(ll i1=0;i1<row;i1++){
				id(i1,i1)=1;
			}
			return id;
		}else{
			matrix2d<T> temp = powmod(b/2,m);
			temp = temp .dot(temp);
			temp%=m;
			if(b%2==1){
				temp=temp.dot(*this);
				temp%=m;
			}
			return temp;
		}
	}


	const T& operator()(ll row,ll col) const{
		return value[row][col];
	}

	T& operator()(ll row,ll col){
		return value[row][col];
	}
private:
	vector<vector <T> > value;
	ll row,col;

};
template<class T> class vector2d{
public:
	T x;
	T y;
	vector2d(){
		x=0;
		y=0;
	}
	vector2d(const T x,const T y){
		this->x=x;
		this->y=y;
	}
	double norm() const{
		return sqrt(x*x+y*y);
	}
	double arg() const{
		return atan2(y,x);
	}
	vector2d operator-(const vector2d& d) const{
		return vector2d(x-d.x,y-d.y);
	}
	vector2d operator+(const vector2d& d) const{
		return vector2d(x+d.x,y+d.y);
	}
	vector2d& operator-=(const vector2d& d){
		x-=d.x;
		y-=d.y;
		return *this;
	}
	vector2d& operator+=(const vector2d& d){
		x+=d.x;
		y+=d.y;
		return *this;
	}
	vector2d operator*(const T d) const{
		vector2d retval(*this);
		retval*=d;
		return retval;
	}
	vector2d& operator*=(const T d){
		x*=d;
		y*=d;
		return *this;
	}
	vector2d operator/(const T d) const{
		vector2d retval(*this);
		retval/=d;
		return retval;
	}
	vector2d& operator/=(const T d){
		x/=d;
		y/=d;
		return *this;
	}
	T dot(const vector2d& d) const{
		return x*d.x+y*d.y;
	}
	vector2d orthogonal() const{
		return vector2d(y,-x);
	}
	operator matrix2d<T>(){
		matrix2d<T> vec(2,1);
		vec(0,0)=x;
		vec(0,1)=y;
		return vec;
	}
};
template<class T> std::ostream& operator<<(std::ostream& it,const vector2d<T> &obj){
	return it<<"("<<obj.x<<","<<obj.y<<")";

}

template<class T> vector2d<T> operator*(const T a,const vector2d<T>& b){
	return b*a;
}

#include <cstdint>
#include <iostream>
#include <utility>
#include <map>

int64_t gcd(int64_t a,int64_t b){//calc gcd
	if(a==0){
		return b;
	}else if(b==0){
		return a;
	}else if(a>b){
		return gcd(a%b,b);
	}else{
		return gcd(b%a,a);
	}
}
std::pair<int64_t,int64_t> extgcd(int64_t a,int64_t b){//a*(pair->first) + b*(pair->second) = gcd(a,b)
	if(a==0){
		return std::make_pair(0,1);
	}else if(b==0){
		return std::make_pair(1,0);
	}else{
		if(a>b){
			std::pair<int64_t,int64_t> d=extgcd(a%b,b);
			return std::make_pair(d.first,d.second-(a/b)*d.first);
		}else{
			std::pair<int64_t,int64_t> d=extgcd(a,b%a);
			return std::make_pair(d.first-(b/a)*d.second,d.second);
		}
	}

}
template<class T>
T normalize_mod(T a,T m){
	return (m+a%m)%m;
}
int64_t mod_inv(int64_t a,int64_t m){//a^-1(mod m),m is a prime number
	int64_t raw=extgcd(a,m).first;
	return normalize_mod(raw,m);;
}
std::map<int64_t,int64_t> factorization(int64_t n){
	std::map<int64_t,int64_t> retval;
	for(int64_t i=2;i*i<=n;i++){
		int64_t counter=0;
		while(n%i==0){
			n=n/i;
			counter++;
		}
		if(counter!=0){
			retval.emplace(i,counter);
		}
	}
	return retval;
}
std::pair<int64_t,int64_t> mod_fact(int64_t n,int64_t m){//n!=first*m^second
	if(n==0){
		return std::make_pair(1,0);
	}else{

		std::pair<int64_t,int64_t> d=mod_fact(n/m,m);
		int64_t second=d.second+n/m;
		int64_t first;
		if((n/m)%2==0){
			first=1;
		}else{
			first=m-1;
		}
		for(int64_t i1=1;i1<=(n%m);i1++){
			first=normalize_mod(first*i1,m);
		}
		return std::make_pair(first,second);
	}
}
ll get_digit_length(ll a){
	ll ans=0;
	while(!(a<=powd(10,ans)-1)){
		++ans;
	}
	return ans;
}
int main(){
	ll l,a,b,m;
	cin>>l>>a>>b>>m;
	l--;
	ll current_s=a;
	ll current_n=a;
	ll current_index = 0;
	ll current_digit = get_digit_length(current_s);
	while(true){
		ll next_digit_index;
		if((powd(10,current_digit)-a)%b==0){
			next_digit_index = (powd(10,current_digit)-a)/b - 1 ;
		}else{
			next_digit_index = (powd(10,current_digit)-a)/b ;
		}
		if(current_digit >= 18||l<next_digit_index){
			//この計算で終わり
			matrix2d<ll> mat(3,3);
			mat(0,0)=(powd(10,current_digit))%m;
			mat(0,1)=b%m;
			mat(0,2)=(a+b)%m;
			mat(1,0)=0;
			mat(1,1)=1;
			mat(1,2)=1;
			mat(2,0)=0;
			mat(2,1)=0;
			mat(2,2)=1;
			matrix2d<ll> mat_powed = mat.powmod(l-current_index,m);
			matrix2d<ll> in = matrix2d<ll>(3,1);
			in(0,0)=current_n%m;
			in(1,0)=current_index%m;
			in(2,0)=1;
			cout<<mat_powed.dot(in)(0,0)%m<<endl;
			break;
		}else{
			matrix2d<ll> mat(3,3);
			mat(0,0)=(powd(10,current_digit))%m;
			mat(0,1)=b%m;
			mat(0,2)=(a+b)%m;
			mat(1,0)=0;
			mat(1,1)=1;
			mat(1,2)=1;
			mat(2,0)=0;
			mat(2,1)=0;
			mat(2,2)=1;
			matrix2d<ll> mat_powed = mat.powmod(next_digit_index-current_index,m);
			matrix2d<ll> in = matrix2d<ll>(3,1);
			in(0,0)=current_n%m;
			in(1,0)=current_index%m;
			in(2,0)=1;

			current_index = next_digit_index;
			current_n = mat_powed.dot(in)(0,0)%m;
		}
		current_digit++;

	}
}


Measured memory_bytes: 256