#include <iostream>

#define NV(v)#v<<" : "<<(v)
using ull = unsigned long long;

static ull n, m, k, x;
static auto &is = std::cin;
static auto &os = std::cout;

template<class T>
T fast_pow(T b,T e, const T &k){
    T ret{1};
    b%=k;
    while(e>0){
        if(e&1){
            ret = (ret * b)%k;
        }
        e>>=1;
        b = (b*b) %k;
    }
    return ret;
}

int main(){
    // os<<NV(fast_pow(3,3, 1000))<<'\n';
    is>>n>>m>>k>>x;
    os<<((x+m*((ull)(fast_pow(10ull,k,n))%n))%n)<<'\n';
}