#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)

















using vec = vector<ll>;
using mat = vector<vec>;

mat mul(mat a, mat b, ll m){
    mat c(a.size(), vec(b[0].size()));
    
    for(ll i = 0; i < a.size(); i++){
        for(ll k = 0; k < b.size(); k++){
            for(ll j = 0; j < b[0].size(); j++){
                c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % m;
            }
        }
    }
    
    return c;
}

mat POW(mat a, ll n, ll m){
    mat b(a.size(), vec(a.size()));
    
    for(ll i = 0; i < a.size(); i++){
        b[i][i] = 1;
    }
    while(n > 0){
        if(n & 1){
            b = mul(b, a, m);
        }
        a = mul(a, a, m);
        n >>= 1;
    }
    
    return b;
}

ll len(ll x){
    ll res = 0;
    while(x > 0){
        x /= 10;
        res++;
    }
    return res;
}

ll f(ll l, ll a, ll b){
    ll z = len(a);
    ll le = 0, ri = l;
    while(le < ri){
        ll m = (le + ri) / 2;
        if(z == len(a + b * m)){
            le = m + 1;
        }
        else{
            ri = m;
        }
    }
    return le;
}
 
int main(){
    ll l, a, b, m;
    cin >> l >> a >> b >> m;
    
    ll sum = 0;
    while(l > 0){
        ll k = f(l, a, b);
        ll p = 1;
        REP(i, len(a)){
            p *= 10;
            p %= m;
        }
        vec r = {sum, a % m, 1};
        mat x = {{p, 0, 0},
                 {1, 1, 0},
                 {0, b % m, 1}};
        x = POW(x, k, m);
        vec t(3);
        t[0] = (r[0] * x[0][0] + r[1] * x[1][0] + r[2] * x[2][0]) % m;
        t[1] = (r[0] * x[0][1] + r[1] * x[1][1] + r[2] * x[2][1]) % m;
        t[2] = (r[0] * x[0][2] + r[1] * x[1][2] + r[2] * x[2][2]) % m;
        
        sum = t[0];
        l -= k;
        a += b * k;
    }
    cout << sum << endl;
}