#include<cstdio>
int main(){
//freopen("circle.in","r",stdin);
//freopen("circle.out","w",stdout);
long long n,m,k,x,ans=1,a,b;
scanf("%lld%lld%lld%lld",&n,&m,&k,&x);
a=10; b=k;
while(b){
if(b%2) ans=(ans*a)%n;
b/=2; a=(a*a)%n;
}
printf("%lld\n",(x+m*ans%n)%n);
return 0;
}