#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(long long n, long long A, long long B, long long M) {
        MOD = M;

        auto length = [&](long long x) {
            long long y = A + x * B;
            int len = 0;
            while (y != 0) {
                ++len;
                y /= 10;
            }
            return len;
        };

        auto search = [&](long long L, int len) {
            long long l = L, r = n - 1;
            while (l < r) {
                auto m = (l + r + 1) >> 1;
                if (length(m) <= len) {
                    l = m;
                } else {
                    r = m - 1;
                }
            }
            return l;
        };


  
        vector<long long> res{0, A % MOD, B % MOD};

        vector<vector<long long>> mat(3, vector<long long>(3, 0));
        mat[0][0] = 1;
        mat[0][1] = 1;
        mat[1][1] = 1;
        mat[1][2] = 1;
        mat[2][2] = 1;
        for (long long i = 0; i < n; ++i) {
            auto l = i;
            int len = length(l);
            auto r = search(l, len);
            
            mat[0][0] = powM(10, len);
            auto MAT = matPow(mat, r - l + 1);
            res = matXvec(MAT, res);
            
            // printMat(mat);
            // printMat(MAT);
            // cout << l << " " << r << " " << res[0] << " " << res[1] << " " << mat[0][0] << " " << l << " " << r - l + 1 <<   endl;
            i = r;

        }

        return res[0];
    }
private:
    long long MOD;

    long long powM(long long x, long long e) {
        long long res = 1;
        x %= MOD;
        while (e > 0) {
            if (e & 1) {
                (res *= x) %= MOD;
            }
            (x *= x) %= MOD;
            e >>= 1;
        }
        return res;
    }

    vector<vector<long long>> matXmat(const vector<vector<long long>>& A, const vector<vector<long long>>& B) {
        int n = A.size();
        int m = B.size();
        assert(A[0].size() == B.size());
        int l = B[0].size();

        vector<vector<long long>> res(n, vector<long long>(l, 0));
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                for (int k = 0; k < l; ++k) {
                    res[i][k] += A[i][j] * B[j][k] % MOD;
                    if (res[i][k] >= MOD) {
                        res[i][k] -= MOD;
                    }
                }
            }
        }

        return res;
    }

    vector<vector<long long>> matPow(vector<vector<long long>> A, long long e) {
        int n = A.size();
        assert(n == A[0].size());
        vector<vector<long long>> res(n, vector<long long>(n, 0));
        for (int i = 0; i < n; ++i) {
            res[i][i] = 1;
        }

        while (e > 0) {
            if (e & 1) {
                res = matXmat(res, A);
            }
            A = matXmat(A, A);
            e >>= 1;
        }
        return res;
    }

    vector<long long> matXvec(const vector<vector<long long>>& A, const vector<long long>& B) {
        int n = A.size();
        int m = B.size();
        assert(A[0].size() == m);

        vector<long long> res(n, 0);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                res[i] += A[i][j] * B[j] % MOD;
                if (res[i] >= MOD) {
                    res[i] -= MOD;
                }
            }
        }
        return res;
    }

    void printVec(const vector<long long>& A) {
        for (auto x : A) {
            cout << x << " ";
        }
        cout << "\n";
    }

    void printMat(const vector<vector<long long>>& M) {
        for (int i = 0; i < M.size(); ++i) {
            for (int j = 0; j < M[0].size(); ++j) {
                cout << M[i][j] << " ";
            }
            cout << "\n";
        }
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long L, A, B, M;
    cin >> L >> A >> B >> M;
    Solution sol;
    cout << sol.solve(L, A, B, M) << "\n";

    return 0;
}

Measured memory_bytes: 256