#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
ll mod;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct Matrix {
    mint m[3][3];
    Matrix(vector<mint> v) {
        rep(i, 9) {
            m[i/3][i%3] = v[i];
        }
    }
};

Matrix multiple(Matrix a, Matrix b) {
    vector<mint> v(9);
    rep(i, 9) {
        ll x = i/3;
        ll y = i%3;
        rep(j, 3) {
            v[i] += a.m[x][j]*b.m[j][y];
        }
    }
    return Matrix(v);
}

Matrix power(Matrix a, ll n) {
    if (n==0) {
        vector<mint> v(9);
        rep(i, 9) {
            if (i==0 || i==4 || i==8) v[i] = 1;
            else v[i] = 0;
        }
        return Matrix(v);
    }
    if (n==1) return a;
    if (n%2==0) {
        return power(multiple(a, a), n/2);
    }
    return multiple(a, power(a, n-1));
}



int main(){
    ll l, a, b;
    cin >> l >> a >> b >> mod;
    if (l==1) {
        cout << a%mod << endl;
        return 0;
    }
    ll keta = 1;
    mint ans = 0;
    while (1) {
        if (keta>18) return -1;
        ll il = 1;
        ll ir = 1;
        //ir = ((pow(10LL, keta)-1)-a);
        rep(i, keta) ir *= 10;
        ir -= (1+a);
        if (ir<0) {
            keta++;
            continue;
        }
        else ir /= b;
        //il = (pow(10LL, keta-1)-1-a);
        rep(i, keta-1) il *= 10;
        il -= (1+a);
        if (il<0) il = -1LL;
        else il /= b;
        ll num = ir - il;
        num = min(num, l);
        if (num==0) {
            keta++;
            continue;
        }
        ir = il + num;
        l -= num;

        //debug(il);
        //debug(ir);
        mint z = mint(10).pow(keta);
        vector<mint> initial = {z, 1, 0, 0, 1, mint(b), 0, 0, 1};

        Matrix matrix(initial);
        Matrix final = power(matrix, num);
        mint prev = ans;
        ans *= (final.m[0][0]);
        ans += final.m[0][1]*mint(a+b*(il+1));
        ans += final.m[0][2];
        mint xx = prev*final.m[1][0] + final.m[1][1]*mint(a+b*(il+1)) + final.m[1][2];
        mint yy = prev*final.m[2][0] + final.m[2][1]*mint(a+b*(il+1)) + final.m[2][2];
        if (xx.x != mint(a+b*(ir+1)).x) {
            return -1;
        }
        if (yy.x!=1) {
            return -1;
        }
        //debug(ans);
        //ll res = final.m[0][0]*
        //ans = ans*(mint(10).pow(total)) + res;
        if (l==0) break;
        keta++;
    }
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256