noip2013d1t1(转圈游戏)
//快速幂
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,x;
long long k;
int ans=1;
int fstpow(int a,long long b)
{
while(b>0)
{
if(b%2==1)
{
ans=(ans*a)%n;
}
a=a*a%n;
b/=2;
}
return ans%n;
}
int main()
{
cin>>n>>m>>k>>x;
cout<<(x%n+m*fstpow(10,k))%n<<endl;
return 0;
}