#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct ModInt {
    ModInt() {}
    ModInt(ll k) : i(k % Mod) {}
    ModInt operator+(ModInt m) const {
        ModInt r;
        r.i = i + m.i;
        if (r.i >= Mod) r.i -= Mod;
        return r;
    }
    ModInt operator-(ModInt m) const {
        ModInt r;
        r.i = i - m.i;
        if (r.i < 0) r.i += Mod;
        return r;
    }
    ModInt operator*(ModInt m) const {
        ModInt r;
        r.i = (ll)i * m.i % Mod;
        return r;
    }
    ModInt &operator+=(ModInt m) {
        i += m.i;
        if (i >= Mod) i -= Mod;
        return *this;
    }
    ModInt &operator-=(ModInt m) {
        i -= m.i;
        if (i < 0) i += Mod;
        return *this;
    }
    ModInt &operator*=(ModInt m) {
        i = (ll)i * m.i % Mod;
        return *this;
    }
    ModInt operator-() const {
        ModInt r;
        r.i = i == 0 ? 0 : Mod - i;
        return r;
    }
    ModInt pow(ll k) const {
        ModInt r = 1, t = *this;
        for (; k != 0; k /= 2) {
            if (k & 1) r *= t;
            t *= t;
        }
        return r;
    }
    ////Modが素数のときのみ
    //ModInt inv() const {
    //    return pow(Mod - 2);
    //}
    //ModInt operator/(ModInt m) const {
    //    return *this * m.inv();
    //}
    //ModInt &operator/=(ModInt m) {
    //    return *this *= m.inv();
    //}
    static int Mod;
    int i;
};
int ModInt::Mod;

template <class T, int N>
struct ColumnVector {
    struct SquareMatrix {
        static SquareMatrix E() {
            SquareMatrix r;
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    r.a[i][j] = i == j;
                }
            }
            return r;
        }
        ColumnVector operator*(const ColumnVector &v) const {
            ColumnVector r;
            for (int i = 0; i < N; i++) {
                T t = 0;
                for (int k = 0; k < N; k++) {
                    t += a[i][k] * v.a[k];
                }
                r.a[i] = t;
            }
            return r;
        }
        SquareMatrix operator*(const SquareMatrix &x) const {
            SquareMatrix r;
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    T t = 0;
                    for (int k = 0; k < N; k++) {
                        t += a[i][k] * x.a[k][j];
                    }
                    r.a[i][j] = t;
                }
            }
            return r;
        }
        SquareMatrix pow(ll k) const {
            SquareMatrix r = E(), t = *this;
            for (; k != 0; k /= 2) {
                if (k & 1) r = r * t;
                t = t * t;
            }
            return r;
        }
        void print() const {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    cout << a[i][j].i << " \n"[j == N - 1];
                }
            }
        }
        T a[N][N];
    };
    void print() const {
        for (int i = 0; i < N; i++) {
            cout << a[i].i << " \n"[i == N - 1];
        }
    }
    T a[N];
};

int main() {
    ll l, a, b;
    cin >> l >> a >> b;

    cin >> ModInt::Mod;
    ColumnVector<ModInt, 3> v = { 0, a, b };//ModIntのコンストラクタでmodとってくれる

    ll c = a + b * l;//最後の項の次
    ll d0 = 10;
    //d0=10^d d0/10以上d0未満つまりd桁の部分を処理する 1桁以上18桁以下とわかっている
    for (int d = 1; d <= 18; d++, d0 *= 10) {
        if (a >= d0) continue;

        ll k = (min(d0, c) - a + (b - 1)) / b;

        //a + (a+b)*10^d + (a+b*2)*10^(d*2) + ... k項
        //全体の桁数がllに収まらないのでは？18桁の数が9*10^17個あったら収まらない
        //逆や 現在の値を10^d倍しa+b*iを足すのをk回やる
        decltype(v)::SquareMatrix x = { d0, 1, 0, 0, 1, 1, 0, 0, 1 };
        v = x.pow(k) * v;

        a += b * k;
        if (a == c) break;
    }

    cout << v.a[0].i << endl;

    //Lがクソでかい 桁数は高々18なので桁数が増える回数も高々18回
    //各桁数について考えればよい 等比数列の和と考えられないけどまあそんな感じの k項
    //      s = a + (a - b) * 10^d + (a - b*2) * 10^(d*2) + ... + (a - b*(k-1)) * 10^(d*(k-1))
    // 10^d*s =           a * 10^d + (a - b*1) * 10^(d*2) + ...                                + (a - b*(k-1)) * 10^(d*k)
    // (10^d - 1)*s= (a - b*(k-1)) * 10^(d*k) - a + b * (10^d + 10^(d*2) + ... + 10^(d*(k-1)))

    // t = 10^d + 10^(d*2) + ... + 10^(d*(k-1))
    //10^d*t=10^(d*2)+...
    // (10^d - 1)*t=10^(d*k)-10^d
    // t=(10^(d*k)-10^d) / (10^d - 1)
    // A / B mod M 

    return 0;
}

Measured memory_bytes: 256