#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

ll mod;

class Matrix
{
public:
    vector<vector<ll>> M;

    Matrix(int h, int w)
    {
        M = vector<vector<ll>>(h, vector<ll>(w));
    }

    vector<ll> &operator[](int i)
    {
        return M[i];
    }
};

Matrix operator*(Matrix x, Matrix y)
{
    int xh = x.M.size(), xw = x[0].size();
    int yh = y.M.size(), yw = y[0].size();
    if (xw != yh)
        throw invalid_argument("Sizes do not match.");
    Matrix res(xh, yw);
    forn(i, xh) forn(j, yw)
    {
        res[i][j] = 0;
        forn(k, xw) res[i][j] += ((x[i][k] % mod) * (y[k][j] % mod)) % mod, res[i][j] %= mod;
    }
    return res;
}

template <typename T>
T quickpow(T b, ll e)
{
    T cur = b;
    T ans = b;
    e--;
    while (e)
    {
        if (e & 1)
            ans = ans * cur;
        cur = cur * cur;
        e >>= 1;
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll l, a, b;
    cin >> l >> a >> b >> mod;

    ll pow10[20];
    ll cur = 1;
    forn(i, 19) pow10[i] = cur, cur *= 10;

    Matrix ans(3, 1);
    ans.M = {{0}, {a}, {b}};
    forn(x, 19)
    {
        if (pow10[x + 1] <= a)
            continue;
        ll L = (pow10[x + 1] - a + b - 1) / b - (max(pow10[x], a) - a + b - 1) / b;
        L = min(L, l), l -= L;
        Matrix M(3, 3);
        M.M = {{pow10[x + 1] % mod, 1, 0}, {0, 1, 1}, {0, 0, 1}};
        if (L > 0)
            ans = quickpow(M, L) * ans;
    }
    cout << ans[0][0] << endl;
    return 0;
}