#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cINF ((1ull<<62)-1)
#define cINFINT ((1<<30)-1)

template< typename T >
class Matrix
{
public:
	explicit Matrix( size_t row_size, size_t col_size )
	{
		mElement.assign( row_size, vector<T>() );
		REP( i, row_size ) mElement[i].assign( col_size, T(0) );
	}

	const vector<T>& operator[] ( size_t row ) const
	{ return mElement[row]; }
	vector<T>& operator[] ( size_t row )
	{ return mElement[row]; }

	const size_t rowSize() const
	{ return mElement.size(); }
	const size_t colSize() const
	{ return mElement[0].size(); }

protected:
	vector<vector<T>> mElement;
};

template< typename T >
class SquareMatrix : public Matrix<T>
{
public:
	explicit SquareMatrix( size_t size )
		: Matrix<T>( size, size )
	{}

	void identity()
	{
		REP( i, this->rowSize() ) REP( j, this->colSize() )
			(*this)[i][j] = i == j ? T(1) : T(0);
	}

	SquareMatrix<T> operator* ( const SquareMatrix& rhs ) const
	{
		size_t size = min( this->colSize(), rhs.colSize() );
		SquareMatrix<T> ret( size );
		REP( i, size )
		REP( k, size )
		REP( j, size )
		{
			ret[i][j] = ret[i][j] + (*this)[i][k] * rhs[k][j];
		}
		return ret;
	}

	SquareMatrix<T> operator^ ( size_t n ) const
	{
		SquareMatrix base = *this;
		SquareMatrix ret( this->rowSize() );
		ret.identity();
		while( n > 0 )
		{
			if( n & 1 ) ret = ret * base;
			base = base * base;
			n >>= 1;
		}
		return ret;
	}

	SquareMatrix<T> mul ( const SquareMatrix& rhs, ll mod ) const
	{
		size_t size = min( this->colSize(), rhs.colSize() );
		SquareMatrix<T> ret( size );
		REP( i, size )
		REP( k, size )
		REP( j, size )
		{
			ret[i][j] = (ret[i][j] + (*this)[i][k] * rhs[k][j] % mod) % mod;
		}
		return ret;
	}

	SquareMatrix<T> pow ( size_t n, ll mod ) const
	{
		SquareMatrix base = *this;
		SquareMatrix ret( this->rowSize() );
		ret.identity();
		while( n > 0 )
		{
			if( n & 1 ) ret = ret.mul( base, mod );
			base = base.mul( base , mod );
			n >>= 1;
		}
		return ret;
	}
};

template <typename T>
void calcPow_mod( T x, vector<T>& powArray, T mod )
{
	REP( i, powArray.size() ) if( i != 0 )
		powArray[i] = powArray[i - 1] * x % mod;
}

int main()
{
    ll l,a,b,mod; cin>>l>>a>>b>>mod;
    vector<ll> powAry( 19, 1 );
    calcPow_mod<ll>( 10, powAry, cINF );
    auto add = [&mod]    ( ll a, ll b ) { return ( a + b ) % mod; };
    auto mul = [&mod]    ( ll a, ll b ) { return a * b % mod; };

    auto solve = [&mod, &b, &powAry, add, mul]
    (ll& ans, ll start, ll end, ll d)
    {
        ll n = ( end - start ) / b + 1;
        SquareMatrix<ll> mtx(3);
        mtx[0][0] = powAry[d]%mod; mtx[0][1] = 1; mtx[0][2] = 0;
        mtx[1][0] = 0; mtx[1][1] = 1; mtx[1][2] = b%mod;
        mtx[2][0] = 0; mtx[2][1] = 0; mtx[2][2] = 1;
        mtx = mtx.pow( n, mod );
        ans = add( mul( ans, mtx[0][0] ), mul( start%mod, mtx[0][1] ) );
        ans = add( ans, mtx[0][2] );
    };

    ll start = a;
    ll end = a + b * ( l - 1 );
    ll ans = 0;
    REP( i, 19 ) if( i != 0 ) if( start < powAry[i] )
    {
        ll dend = ( powAry[i] - 1 - start ) / b * b + start;
        if( dend > end ) dend = end;
        solve( ans, start, dend, i );
        if( dend == end ) break;
        start = dend + b;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256