#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

Int L, A, B, M;

typedef struct m {
    Int m[3][3];
}Matrix;

Matrix operator * (Matrix a, Matrix b) {
    Matrix c;
    for(int i = 0;i < 3;i++) {
        for(int j = 0;j < 3;j++) {
            c.m[i][j] = 0;
            for(int k = 0;k < 3;k++) {
                c.m[i][j] = (c.m[i][j]+ (a.m[i][k]*b.m[k][j]%M))%M;
            }
        }
    }

    return c;
}

Matrix create(Int op, Int b) {
    Matrix A;
    A.m[0][0] = op % M;
    A.m[0][1] = 0;
    A.m[0][2] = 0;
    A.m[1][0] = 1;
    A.m[1][1] = 1;
    A.m[1][2] = 0;
    A.m[2][0] = 0;
    A.m[2][1] = B%M;
    A.m[2][2] = 1;

    return A;
}

Matrix pow(Matrix x, Int y) {
    Matrix ans;
    if(y == 1)
        return x;
    ans = pow(x*x,y/2);
    if(y&1) {
        ans = ans*x;
    }
    return ans;
}

int main(void) {
    cin>>L>>A>>B>>M;
    Int op = 10;
    Int ans = 0;
    Int o = 0;
    L--;
    for(int i = 1;i <= 19;i++) {
        Int l = o,r = L,p = -1;
        while(l <= r) {
            Int mid = (l+r)/2;
            if(mid*B+A < op) {
                p = mid;
                l = mid+1;
            } else {
                r = mid-1;
            }
        }
        if(p != -1) {
            Matrix a = create(op,B);
            a = pow(a,p-o+1);
            Int t = (B*o%M+A) % M;
            ans = (ans * a.m[0][0]%M + t*a.m[1][0]%M+a.m[2][0])%M;
            o = p+1;
        }
        if(o > L)
            break;
        op *= 10;
    }
    cout<<ans<<endl;

    return 0;
}
