#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

template<typename T>
class Matrix {
    private:
        using array = vector<T>;
        using matrix = vector<array>;
        size_t row_size, column_size;
        matrix data;
    public:
        Matrix(size_t row, size_t column):data(row, array(column, T())) {
            row_size = row;
            column_size = column;
        }
        Matrix(matrix new_data):data(new_data){}

        size_t row() const {return row_size;}
        size_t col() const {return column_size;}

        array& operator[] (size_t idx) {
            return data[idx];
        }
        const array& operator[] (size_t idx) const {
            return data[idx];
        }
        const Matrix operator+ (const Matrix& X) const {
            Matrix res(row_size, column_size);
            for (int i = 0; i < (int)res.row(); i++) {
                for (int j = 0; j < (int)res.col(); j++) {
                    res[i][j] = data[i][j] + X[i][j];
                }
            }
            return res;
        }
        Matrix& operator+= (const Matrix& X) {
            for (int i = 0; i < (int)row_size; i++) {
                for (int j = 0; j < (int)column_size; j++) {
                    data[i][j] += X[i][j];
                }
            }
            return *this;
        }
        const Matrix operator- (const Matrix& X) const {
            Matrix res(row_size, column_size);
            for (int i = 0; i < (int)res.row(); i++) {
                for (int j = 0; j < (int)res.col(); j++) {
                    res[i][j] = data[i][j] - X[i][j];
                }
            }
            return res;
        }
        Matrix& operator-= (const Matrix& X) {
            for (int i = 0; i < (int)row_size; i++) {
                for (int j = 0; j < (int)column_size; j++) {
                    data[i][j] -= X[i][j];
                }
            }
            return *this;
        }
        const Matrix operator* (const Matrix& X) const {
            size_t new_row = row_size, new_column = X.col();
            Matrix res(new_row, new_column);
            for (int i = 0; i < (int)res.row(); i++) {
                for (int j = 0; j < (int)res.col(); j++) {
                    for (int k = 0; k < (int)column_size; k++) {
                        res[i][j] += data[i][k] * X[k][j];
                    }
                }
            }
            return res;
        }
        const Matrix operator* (T scalar) const {
            Matrix res(row_size, column_size);
            for (int i = 0; i < res.row(); i++) {
                for (int j = 0; j < res.col(); j++) {
                    res[i][j] = data[i][j] * scalar;
                }
            }
            return res;
        }
        Matrix& operator*= (T scalar) {
            for (int i = 0; i < (int)row_size; i++) {
                for (int j = 0; j < (int)column_size; j++) {
                    data[i][j] *= scalar;
                }
            }
            return *this;
        }
        const Matrix operator% (T mod) const {
            Matrix res(data);
            for (int i = 0; i < (int)res.row(); i++) {
                for (int j = 0; j < (int)res.col(); j++) {
                    res[i][j] %= mod;
                }
            }
            return res;
        }
        Matrix& operator%= (T mod) {
            for (int i = 0; i < (int)row_size; i++) {
                for (int j = 0; j < (int)column_size; j++) {
                    data[i][j] %= mod;
                }
            }
            return *this;
        }

        static Matrix identity(size_t row, size_t col) {
            Matrix<T> res(row, col);
            for (int i = 0; i < (int)res.row(); i++) {
                res[i][i] = 1;
            }
            return res;
        }
};

ll MOD;

ll lower_num(ll a, ll d, ll x) {
    // 初項a, 差dの数列においてx以上の最小の項を返す
    if (x <= a) return a;
    return (x - a + d - 1) / d * d + a;
}

Matrix<ll> calc_pow(Matrix<ll> x, ll y) {
    Matrix<ll> z = Matrix<ll>::identity(x.row(), x.col());
    while (y > 0) {
        if (y & 1) {
            z = z * x;
            z %= MOD;
        }
        x = x * x;
        x %= MOD;
        y /= 2;
    }
    return z;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll L, A, B;
    cin >> L >> A >> B >> MOD;
    Matrix<ll> X(1, 3), Y(3, 3);
    // X
    X[0][0] = 0;
    X[0][1] = A;
    X[0][2] = 1;
    // Y
    Y[1][0] = 1;
    Y[1][1] = 1;
    Y[2][2] = 1;
    Y[2][1] = B;
    ll pow_num = 1;
    for (int d = 1; d <= 18; d++) {
        if (L == 0) break;
        Y[0][0] = (pow_num * 10) % MOD;
        ll high = lower_num(A, B, pow_num * 10);
        ll low = lower_num(A, B, pow_num);
        ll Cd = min((high - low) / B, L);
        L -= Cd;
        Matrix<ll> Z = calc_pow(Y, Cd);
        X = X * Z;
        X %= MOD;
        pow_num *= 10;
    }
    cout << X[0][0] << endl;
    return 0;
}

Measured memory_bytes: 256