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

template <typename T>
struct Matrix {
    vector<vector<T>> mat;
    Matrix(int n, int m, T val = 0) : mat(n, vector<long long>(m, val)) {};
    void init(int n, int m, T val = 0) {mat.assigin(n, vector<long long>(m, val));}
    size_t size() const {return mat.size();}
    inline vector<long long>& operator[](int i) {return mat[i];}
};

long long MOD;

template <typename T>
Matrix<T> operator*(Matrix<T> A, Matrix<T> B) {
    Matrix<T> C(A.size(), B[0].size());
    for(int i = 0; i < A.size(); ++i) {
        for(int j = 0; j < B[0].size(); ++j) {
            for(int k = 0; k < B.size(); ++k) {
                C[i][j] = (C[i][j] + A[i][k] * B[k][j] % MOD) % MOD;
            }
        }
    }
    return C;
}

template <typename T>
Matrix<T> pow(Matrix<T> A, long long n) {
    Matrix<T> C(A.size(), A.size());
    for(int i = 0; i < A.size(); ++i) C[i][i] = 1;
    while(n > 0) {
        if(n & 1) C = C * A;
        A = A * A;
        n >>= 1;
    }
    return C;
}

using mat = Matrix<long long>;
using vec = vector<long long>;

vec pro(mat A, vec X, long long C){
    vec ret(3, 0);
    mat Apro = pow(A, C);

    for(int i=0; i<3; ++i) {
        for(int j=0; j<3; ++j) {
            ret[i] = (ret[i] + Apro[i][j] * X[j] % MOD) % MOD;
        }
    }
    return ret;
}

long long powmod(long long x, long long n) {
    long long ret = 1;
    while(n > 0) {
        if(n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

int main() {
    long long L, A, B;
    cin >> L >> A >> B >> MOD;

    int start = 0;
    long long tmp = 1;
    for(; start < 18; ++start) {
        if(A >= tmp && A < tmp * 10) break;
        tmp *= 10LL;
    }

    vec C(18);
    long long prev = A - B, cnt = 0;

    for(int i=start; i<18; ++i) {
       C[i] = ((long long)pow(10, i + 1) - prev) / B;
       if(prev + B * C[i] == (long long)pow(10, i + 1)) --C[i];
       C[i] = min(C[i], L - cnt);
       cnt += C[i];
       if(cnt == L) break;
       prev += B * C[i];
    }

    vec X = {0, A, B};
    mat coeff(3, 3);
    coeff[0] = {1, 1, 0};
    coeff[1] = {0, 1, 1};
    coeff[2] = {0, 0, 1};
    for(int d=0; d<18; ++d) {
        coeff[0][0] = powmod(10, d + 1);
        X = pro(coeff, X, C[d]);
    }

    cout << X[0] % MOD << endl;
}