#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
FILE *in,*out;
long n;
long long ans;
long long qm(long k){
long long ans=0;
if(k==1) return 10%n;
ans=qm(k/2)%n;
ans=(ans*ans)%n;
if(k%2!=0)
ans=(ans*10)%n;
return ans;
}
int main(){
long a,b,c,m,k,x;
in=fopen("circle.in","r");
out=fopen("circle.out","w");
fscanf(in,"%ld %ld %ld %ld",&n,&m,&k,&x);
a=x%n;
b=m%n;
c=qm(k);
ans=(a+b*c)%n;
fprintf(out,"%lld",ans);
return 0;
}
#include <stdlib.h>
#include <math.h>
#include <string.h>
FILE *in,*out;
long n;
long long ans;
long long qm(long k){
long long ans=0;
if(k==1) return 10%n;
ans=qm(k/2)%n;
ans=(ans*ans)%n;
if(k%2!=0)
ans=(ans*10)%n;
return ans;
}
int main(){
long a,b,c,m,k,x;
in=fopen("circle.in","r");
out=fopen("circle.out","w");
fscanf(in,"%ld %ld %ld %ld",&n,&m,&k,&x);
a=x%n;
b=m%n;
c=qm(k);
ans=(a+b*c)%n;
fprintf(out,"%lld",ans);
return 0;
}