#include<cstdio>
#include<iostream>
using namespace std;
long long n,m,k,x;
long long quick_pow(long long b,long long a){
if(!a) return 1;
if(a&1) return(quick_pow(b,a-1)%n*b)%n;
long long t=quick_pow(b,a/2)%n;
return (t*t)%n;
}
int main(){
cin>>n>>m>>k>>x;
long long ans=(x+m%n*quick_pow(10,k))%n;
cout<<ans<<endl;
return 0;
}