#include <bits/stdc++.h>

using namespace std;

typedef __int128 very_long;

namespace long_mul {


very_long mul(very_long a, very_long b, very_long mod) {
    if (b == 0) {
        return 0;
    }
    if (b % 2 == 0) {
        return (2 * mul(a, b / 2, mod)) % mod;
    }
    return (a + mul(a, b - 1, mod)) % mod;
}

very_long power(very_long a, very_long b, very_long mod) {
    if (b == 0) {
        return 1 % mod;
    }
    if (b % 2 == 0) {
        return power(mul(a, a, mod), b / 2, mod);
    }
    return mul(a, power(a, b - 1, mod), mod);
}

}

int mod;

int mul(int x, int y) {
    return (1LL * x * y) % mod;
}

int power(int a, unsigned long long b) {
    if (b == 0) {
        return 1;
    }
    if (b % 2 == 0) {
        return power(mul(a, a), b / 2);
    }
    return mul(a, power(a, b - 1));
}

int phi(int x) {
    int result = x;
    for (int i = 2; i * i <= x; ++i) {
        if (x % i == 0) {
            while (x % i == 0) {
                x /= i;
            }
            result -= result / i;
        }
    }
    if (x > 1) {
        result -= result / x;
    }
    return result;
}

int rp;

int inv(int x) {
    //cout << "$" << mul(x, power(x, rp));
    return power(x, rp);
}

long long n, a, b;
vector<int> len;
vector<long long> v;

int get_len(long long x) {
    int res = 0;
    while (x) {
        ++res;
        x /= 10;
    }
    return res;
}

int geom(long long to, very_long p) {
    if (p == 0) {
        return 1;
    }
    if (p == 1) {
        return to % mod;
    }
    return long_mul::power(p, to, mod * (p - 1)) / (p - 1);
}

int calc(int len, long long to, long long x) {
    int p = power(10, len);
    x %= mod;
    int y = (-b % mod + mod) % mod;

    //cout << x << " " << y << " " << p << endl;
    int res = mul(x, geom(to + 1, p));
    very_long big_mod = mod;
    big_mod *= p - 1;
    big_mod *= p - 1;
    very_long add = 0;
    if (p == 0) {
    } else if (p == 1) {
        add = to;
        add *= to + 1;
        add /= 2;
        add %= mod;
    } else {
        add = long_mul::mul(to, long_mul::power(p, to + 1, big_mod), big_mod);
        add += 1 + big_mod - long_mul::mul(to + 1, long_mul::power(p, to, big_mod), big_mod);
        add %= big_mod;
        add = long_mul::mul(add, p, big_mod);
        add /= p - 1;
        add /= p - 1;
    }
    res += mul(add, y);
    res %= mod;
    //cout << res << endl;
    return res;
}

int calc(int len, long long l, long long r, unsigned long long tot_len) {
    int k = power(10, tot_len);
    //cout << k << " " << mul(k, calc(len, r - l, a + r * b)) << endl;
    return mul(k, calc(len, r - l, a + r * b));
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> a >> b >> mod;
    rp = phi(mod) - 1;
    long long cur = 0;
    while (cur < n) {
        v.push_back(cur);
        int cur_len = get_len(a + b * cur);
        len.push_back(cur_len);
        long long l = 0, r = n;
        while (r - l > 1) {
            long long mid = (l + r) / 2;
            if (get_len(a + b * mid) > cur_len) {
                r = mid;
            } else {
                l = mid;
            }
        }
        cur = r;
    }
    v.push_back(cur);
    int ans = 0;
    unsigned long long tot_len = 0;
    for (int i = 0; i < len.size(); ++i) {
        tot_len += 1LLU * len[i] * (v[i + 1] - v[i]);
    }
    for (int i = 0; i < len.size(); ++i) {
        //cout << len[i] << " [" << v[i] << " " << v[i + 1] << ")" << endl;
        tot_len -= 1LLU * len[i] * (v[i + 1] - v[i]);
        ans += calc(len[i], v[i], v[i + 1] - 1, tot_len);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256