#include<bits/stdc++.h>
using namespace std;
int m,n,k,l,x;
int ksm(int k)
{ if (k==1) return 10;
int op=1;
if (k%2==0) op=1;
else op=10;
int temp=ksm(k/2)%n;
return (temp*temp)%n*op;
}
int main()
{ freopen("CircleNOIP2013.in","r",stdin);
freopen("CircleNOIP2013.out","w",stdout);
scanf("%d%d%d%d",&n,&m,&k,&x);
int ans=ksm(k)*m%n;
printf("%d",(ans+x)%n);
}
/*
29221 6118 30423181 11728
648
*/