#include <bits/stdc++.h>
const int default_mod = 1000000007;
template<typename T>
class Matrix {
    int sz;
    int mod;
public:
    std::vector<std::vector<T>> A;
    int size() {
        return sz;
    }
    Matrix(std::vector<std::vector<T>> v, int m = default_mod) {
        mod = m;
        sz = v.size();
        assert(sz > 0);
        assert(sz == (int)(v[0].size()));
        A.clear();
        A.resize(sz, std::vector<T>(sz, 0));
        for(int i=0;i<sz;++i) {
            for(int j=0;j<sz;++j) {
                A[i][j] = v[i][j];
            }
        }
    }
    Matrix(Matrix<T> &B, int m = default_mod) {
        mod = m;
        sz = B.sz;
        A.clear();
        A.resize(sz, std::vector<T>(sz));
        for(int i=0;i<sz;++i) {
            for(int j=0;j<sz;++j) {
                A[i][j] = B[i][j];
            }
        }
    }
    Matrix(int n, int m = default_mod) {
        mod = m;
        sz = n;
        A.clear();
        A.resize(sz, std::vector<T>(sz, 0));
    }
    void to_I() {
        A.clear();
        A.resize(sz, std::vector<T>(sz, 0));
        for(int i=0;i<sz;++i) {
            A[i][i] = 1;
        }
    }
    void print() {
        for(int i=0;i<sz;++i) {
            for(int j=0;j<sz;++j) {
                std::cout << A[i][j] << " ";
            }
            std::cout << std::endl;
        }
    }
    std::vector<T>&operator[](int i) {
        return A[i];
    }
    Matrix<T> &operator+=(Matrix<T> B) {
        for(int i=0;i<sz;++i) {
            for(int j=0;j<sz;++j) {
                A[i][j] += B[i][j];
                A[i][j] %= mod;
            }
        }
        return (*this);
    }
    Matrix<T> &operator*=(Matrix<T> B) {
        std::vector<std::vector<T>> C(sz, std::vector<T>(sz, 0));
        for(int i=0;i<sz;++i) {
            for(int j=0;j<sz;++j) {
                for(int k=0;k<sz;++k) {
                    C[i][j] += (A[i][k] * B[k][j]) % mod;
                    C[i][j] %= mod;
                }
            }
        }
        A = C;
        return (*this);
    }
    std::vector<T> operator *(std::vector<T> v) {
        assert(sz = (int)(v.size()));
        std::vector<T> res(sz, 0);
        for(int i=0;i<sz;++i) {
            for(int j=0;j<sz;++j) {
                res[i] += (A[i][j] * v[j]) % mod;
                res[i] %= mod;
            }
        }
        return res;
    }
    Matrix<T> &operator^=(long long k) {
        Matrix<T> B(sz, mod);
        B.to_I();
        while(k > 0) {
            if(k&1) B *= *this;
            *this *= *this;
            k = k >> (1ll);
        }
        A = B.A;
        return (*this);
    }
};
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll l, a, b; cin >> l >> a >> b;
  int m; cin >> m;
  vector<ll> pos(18), cnt(18);
  pos[0] = 0;
  cnt[0] = 0;
  ll now = 1;
  ll default_len = (1000000000000000000ll - a) / b;
  for(int i=1;i<18;++i) {
    now *= 10;
    ll left = a, len = default_len;
    while(len > 1) {
      bool odd = len % 2 == 1;
      len /= 2;
      ll mid = left + b * len;
      if(mid < now) {
        left = mid;
        if(odd) len++;
      }
    }
    pos[i] = (left - a) / b + 1;
    cnt[i] = pos[i] - pos[i-1];
  }
  now = 1;
  vector<ll> nowv = {0, a, 1};
  for(int i=1;i<=18;++i) {
    now *= 10;
    now %= m;
    vector<vector<ll>> v = {{now, 1, 0}, {0, 1, b}, {0, 0, 1}};
    Matrix<ll> M(v, m);
    if(i == 18 || pos[i] > l) {
      M ^= l - pos[i-1];
      nowv = M * nowv;
      break;
    } else {
      M ^= cnt[i];
      nowv = M * nowv;
    }
  }
  cout << nowv[0] << endl;
}


Measured memory_bytes: 256