#include <bits/stdc++.h>
using namespace std;

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

class mint {
public:
    i64 x,m;
    mint()= default;
    mint(i64 m_, i64 x_) :m(m_), x((x_ % m_ + m_) % m_) {}
    mint operator+() const { return mint(m, x); }
    mint operator-() const { return mint(m, -x); }
    mint& operator+=(const mint& y) {
        if(m == 0){
            assert(y.m != 0);
            m = y.m;
        }
        x = ((x + y.x) % m + m) % m;
        return *this;
    }
    mint& operator-=(const mint& y) { return *this += -y; }
    mint& operator*=(const mint& y) {
        if(m == 0){
            assert(y.m != 0);
            m = y.m;
        }
        x = x * y.x % m;
        return *this;
    }
    mint operator+(const mint& y) const { return mint(m, x) += y; }
    mint operator-(const mint& y) const { return mint(m, x) -= y; }
    mint operator*(const mint& y) const { return mint(m, x) *= y; }
    bool operator==(const mint& y) const { return x == y.x; }
    bool operator!=(const mint& y) const { return !(*this == y); }
};

template <class T>
T rep_pow(T x, int64_t y) {
    T res(1);
    while (y > 0) {
        if (y & 1) res *= x;
        x *= x;
        y >>= 1;
    }
    return res;
}
template <i64 m>
ostream& operator<<(ostream& os, const mint& x) {
    os << x.x;
    return os;
}
i64 abs(const mint& x) { return x.x; }
mint rep_pow(mint x, i64 y){
    mint res(x.m, 1);
    while(y>0){
        if(y & 1) res*=x;
        x*=x;
        y>>=1;
    }
    return res;
}

template <class K>
class matrix {
public:
    int m, n;
    vector<vector<K>> a;
    matrix(int m_, int n_) : m(m_), n(n_), a(m_, vector<K>(n_)) {}
    matrix(const vector<vector<K>>& v) : m(v.size()), n((v.size() == 0 or v[0].size() == 0) ? 0 : v[0].size()), a(v) {}
    //matrix(const matrix<K>& other)=default;
    //~matrix()=default;

    vector<K>& operator[](int i) {
        assert(0 <= i);
        assert(i < m);
        return a[i];
    }
    matrix<K> operator+() const { return *this; }
    matrix<K> operator-() const { return K(-1) * *this; }
    K at(int i, int j) const { return a[i][j]; }

    matrix<K>& operator=(const matrix<K>& other) = default;
    matrix<K>& operator+=(const matrix<K>& other) {
        assert(m == other.m);
        assert(n == other.n);
        for (int i = 0; i < m; ++i)
            for (int j = 0; j < n; ++j) (*this)[i][j] += other[i][j];
        return *this;
    }
    matrix<K>& operator-=(const matrix<K>& other) { return (*this) += -other; }
    matrix<K>& operator*=(const matrix<K>& other) {
        assert(n == other.m);
        vector<vector<K>> b(m, vector<K>(other.n));
        for (int i = 0; i < m; ++i)
            for (int j = 0; j < other.n; ++j)
                for (int k = 0; k < n; ++k) b[i][j] += (*this)[i][k] * other.at(k, j);
        a = b;
        n = other.n;
        return *this;
    }
    matrix<K>& operator/=(const K& k) {
        assert(k != K(0));
        for (int i = 0; i < m; ++i)
            for (int j = 0; j < n; ++j) (*this)[i][j] /= k;
        return *this;
    }
    matrix<K>& operator%=(const K& k) {
        assert(k != K(0));
        for (int i = 0; k < m; ++i)
            for (int j = 0; j < n; ++j) (*this)[i][j] = ((*this)[i][j] + k) % k;
        return *this;
    }
    matrix<K> operator+(const matrix<K>& other) const { return matrix<K>(*this) += other; }
    matrix<K> operator-(const matrix<K>& other) const { return matrix<K>(*this) -= other; }
    matrix<K> operator*(const matrix<K>& other) const { return matrix<K>(*this) *= other; }
    matrix<K> operator/(const K& k) const { return matrix(*this) /= k; }
    matrix<K> operator%(const K& k) const { return matrix(*this) %= k; }

    bool operator==(const matrix<K>& other) const {
        if (m != other.m or n != other.n) return false;
        for (int i = 0; i < m; ++i)
            for (int j = 0; j < n; ++j)
                if ((*this)[i][j] != other[i][j]) return false;
        return true;
    }
    bool operator!=(const matrix<K>& other) const { return !((*this) == other); }

    static matrix<K> E(int m) {
        assert(0 <= m);
        matrix<K> E_(m, m);
        for (int i = 0; i < m; ++i) E_[i][i] = K(1);
        return E_;
    }

    static matrix<K> e(int m, int i) {
        assert(0 <= i);
        assert(i < m);
        matrix<K> e_;
        e_[i][0] = K(1);
        return e_;
    }
};

template <class K>
matrix<K> rep_pow(matrix<K> x, const K e /* = Kの単位元 */, int n, int64_t y) {
    assert(x.m == x.n);
    assert(x.m == n);

    matrix<K> res(n, n);
    for (int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(i == j) res[i][j] = e;
            else res[i][j] = e - e;
        }
    }

    while (y > 0) {
        if (y & 1) res *= x;
        x *= x;
        y >>= 1;
    }
    return res;
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 L,A,B,M;
    cin >> L >> A >> B >> M;

    vector<i64> from(32,-1); // |A+B*from[i]| >= i, |A+B*(from[i]-1)| < i
    rep(i,0,from.size()){
        if(to_string(A+B*(L-1)).length()<i) break;

        i64 lb=-1,ub=L-1;
        while(ub-lb>1){
            i64 mid=(lb+ub)/2;
            if(mid>=0 and to_string(A+B*mid).length()>=i) ub=mid;
            else lb=mid;
        }

        assert(lb==-1 or to_string(A+B*lb).length()<i);
        assert(to_string(A+B*ub).length()>=i);

        from[i]=ub;
    }

    mint ans(M,0);
    {
        matrix<mint> s(3, 1);
        s[0][0]=mint(M,0);
        s[1][0]=mint(M,0);
        s[2][0]=mint(M,1);

        bool dec=true;
        rep(i, 0, from.size()) {
            if (from[i] == -1) break;
            if (i + 1 < from.size() and from[i] == from[i + 1]) continue;

            matrix<mint> x(3, 3);

            x[0][0] = rep_pow(mint(M, 10), i);
            x[0][1] = mint(M, B);
            x[0][2] = mint(M, B);

            x[1][0] = mint(M, 0);
            x[1][1] = mint(M, 1);
            x[1][2] = mint(M, 1);

            x[2][0] = mint(M, 0);
            x[2][1] = mint(M, 0);
            x[2][2] = mint(M, 1);

            i64 k = (i + 1 < from.size() and from[i + 1] == -1) ? (L - from[i]) : (from[i + 1] - from[i]);
            if(dec){
                dec=false;
                --k;
            }
            auto xk=rep_pow(x,mint(M,1), 3, k); // x^k
            s=xk*s;
        }
        ans += s[0][0];
    }
    print(ans.x);
    {
        matrix<mint> s(2, 1);
        s[0][0]=mint(M,0);
        s[1][0]=mint(M,1);
        rep(i, 0, from.size()) {
            if (from[i] == -1) break;
            if (i + 1 < from.size() and from[i] == from[i + 1]) continue;

            matrix<mint> x(2, 2);

            x[0][0] = rep_pow(mint(M, 10), i);
            x[0][1] = mint(M, A);

            x[1][0] = mint(M, 0);
            x[1][1] = mint(M, 1);

            i64 k = (i + 1 < from.size() and from[i + 1] == -1) ? (L - from[i]) : (from[i + 1] - from[i]);
            auto xk=rep_pow(x,mint(M,1), 2, k); // x^k
            s=xk*s;
        }
        ans += s[0][0];
    }

    cout << ans.x << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256