#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:
    long long solve(long long n, long long a, long long b, long long MOD) {
        vector<pair<long long, long long>> P;
        vector<int> lens;

        auto length = [&](long long x) {
            long long y = a + b * x;
            string s = to_string(y);
            return s.length();
        };

        auto search = [&](long long beg, int len) {
            long long l = beg, r = n - 1;

            while (l < r) {
                auto m = (l + r + 1) / 2;
                if (length(m) <= len) {
                    l = m;
                } else {
                    r = m - 1;
                }
            }
            return l;
        };

        int R = 0;
        for (long long i = 0; i < n; ++i) {
            auto l = i;
            auto r = l;
            auto len = length(l);
            r = search(l, len);
            P.emplace_back(l, r);
            lens.push_back(len);
            i = r;
        }

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

        function<long long(long long, long long)> powSum = [&](long long x, long long e) -> long long {
            if (e == 0) {
                return 0LL;
            }
            if (e == 1) {
                return 1;
            }
            x %= MOD;
            auto ne = e >> 1;
            auto off = powM(x, ne);
            auto half = powSum(x, ne);
            // cout << e << " ::: " << off << " " << half << endl;
            long long res = half * (1LL + off) % MOD;
            if (e & 1) {
                (res += powM(x, e - 1)) %= MOD;
            }
            return res;
        };

        function<long long(long long, long long)>  powSum2 = [&](long long x, long long e) -> long long {
            if (e == 0) {
                return 0;
            }
            
            if (e == 1) {
                return 1;
            }
            x %= MOD;

            auto ne = e >> 1;
            auto off = powM(x, ne);
            auto half = powSum2(x, ne);

            // cout << e << " ::::: " << off << " " << half << endl;
            long long res = (half * off) % MOD;
            (res += half) %= MOD;
            (res += powSum(x, ne) * (ne % MOD) % MOD) %= MOD;
            if (e & 1) {
                (res += powSum(x, e)) %= MOD;
            }
            return res;
        };


        long long ret = 0;
        int m = P.size();

        long long offset = 1;
        a %= MOD;
        b %= MOD;
        for (int i = m - 1; i >= 0; --i) {
            long long l = P[i].first;
            long long r = P[i].second;
            long long len = lens[i];

            // cout << l << " " << r << " " << len << " " << offset << endl;

            long long B = powM(10, len);
            long long cnt = r - l + 1;
            
            long long res = 0;
            res += ((a + l % MOD * b) % MOD * powSum(B, cnt)) % MOD;
            res %= MOD;

            res += (b * powSum2(B, cnt - 1)) % MOD;
            res %= MOD;

            (res *= offset) %= MOD;
            (ret += res) %= MOD;

            (offset *= powM(B, r - l + 1)) %= MOD;
        }
        return ret;
    }
};

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: 384