#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<ll> vec;
typedef vector<vec> mat;

// const ll mod = 1000000007;

mat mat_mul(mat &A, mat &B , ll mod){
    mat C(A.size(), vec(B[0].size()));
    for (int i = 0; i < A.size(); i++){
        for (int k = 0; k < B.size(); k++){
            for (int j = 0; j < B[0].size(); j++){
                A[i][k] %= mod;
                B[k][j] %= mod;
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
            }
        }
    }
    return C;
}

mat mat_pow(mat A, ll n, ll mod){
    mat B(A.size(), vec(A.size()));
    for (int i = 0; i < A.size(); i++){
        B[i][i] = 1;
    }
    while(n > 0){
        if(n & 1) B = mat_mul(B, A, mod);
        A = mat_mul(A, A, mod);
        n >>= 1;
    }
    return B;
}

bool C(ll x, ll ten, ll a, ll b){
    ll n = a + b * x;
    return n < ten;
}

int main(){
    ll L, a, b, m;
    cin >> L >> a >> b >> m;
    ll x = 0;
    ll s = a;
    mat X(1, vec(3));
    X[0][0] = x;  X[0][1] = a; X[0][2] = 1; 
    ll ten = 1;
    ll num_old = -1;
    ll num;
    rep(i, 18){
        ten *= 10;
        mat A(3, vec(3));
        A[0][0] = ten % m; A[0][1] = 0; A[0][2] = 0;
        A[1][0] = 1; A[1][1] = 1; A[1][2] = 0;
        A[2][0] = 0; A[2][1] = b % m; A[2][2] = 1;
        ll l = -1;
        ll r = L - 1;
        while(l < r - 1){
            ll mid = (l + r) / 2;
            if(C(mid, ten, a, b)) l = mid;
            else r = mid;
        }
        if(C(l+1, ten, a, b)) num = l + 1;
        else num = l;
        ll numd = num - num_old;
        num_old = num;
        // cout << numd << "abc" << endl;
        // cout << A[0][0] << endl;
        A = mat_pow(A, numd, m);
        // cout << A[0][0] << endl;
        X = mat_mul(X, A, m);
        // cout << X[0][0] << endl;
    }
    s = a + (b * (L - 1));
    // cout << s << endl;
    cout << X[0][0] << endl;
}