#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

ll M;

mat mul (mat &A, mat &B) {
    mat C(A.size(), vec(B[0].size()));
    Rep (i, A.size()) {
        Rep (k, B.size()){
            Rep (j, B[0].size()) {
                C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % M) % M;
            }
        }
    }
    return C;
}

mat matpow(mat A, ll n) {
    mat B(A.size(), vec(A.size()));
    Rep (i, A.size()) {
        B[i][i] = 1;
    }
    while (n > 0) {
        if (n & 1) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll L, A, B;
    cin >> L >> A >> B >> M;

    vector<ll> d(19, 0);
    for (ll i = 1; i <= 18; i++) {
        d[i] = min(((ll)pow(10, i) - A + B - 1) / B, L);
        d[i] = max((ll)0, d[i]);
    }

    for (ll i = 18; i >= 1; i--) {
        d[i] -= d[i-1];
    }

    // for (ll e : d) cout << e << "\n";

    ll X = 0, s = A % M;
    for (ll i = 1; i <= 18; i++) {
        // cout << i << "\n";
        mat a(3, vec(3)), b(3, vec(1));
        a[0][0] = (ll)pow(10, i) % M, a[0][1] = 1, a[0][2] = 0;
        a[1][0] = 0, a[1][1] = 1, a[1][2] = B % M;
        a[2][0] = 0, a[2][1] = 0, a[2][2] = 1;
        b[0][0] = X % M, b[1][0] = s % M, b[2][0] = 1;
        a = matpow(a, d[i]);
        b = mul(a, b);
        X = b[0][0];
        s = b[1][0];
        // cout << X << "\n";
    }

    cout << X << "\n";
}