#include<cstdio>
using namespace std;
long long n,m,k,x;
long long temp=10;
long long Ans;
int main()
{
freopen("CircleNOIP2013.in","r",stdin);
freopen("CircleNOIP2013.out","w",stdout);
scanf("%lld%lld%lld%lld",&n,&m,&k,&x);
Ans=m;
while(k)
{
if(k&1)
{
Ans*=temp;
Ans%=n;
}
temp*=temp;
temp%=n;
k>>=1;
}
Ans+=x;
Ans%=n;
printf("%lld",Ans);
fclose(stdin);
fclose(stdout);
return 0;
}