#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cctype>
#include <queue>
#include <deque>
#include <ctime>
#include <cstring>
#include <string>
#define _e putchar (' ')
#define _v putchar ('\n')
#define ll long long
#define INF 999999999999999999ll
#define INE -999999999999999999ll
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;
inline int lowbit (int x) {
return x&(-x);
}
inline int mx(int x,int y) {
return x>y?x:y;
}
inline int mn(int x,int y) {
return x<y?x:y;
}
inline void r(ll &x) {
ll s=0,w=1;
char ch=getchar ();
while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar ();}
while(ch>='0'&&ch<='9') {s=(s<<1)+(s<<3)+(ch^48); ch=getchar ();}
x=s*w;
}
inline void wr(ll x) {
if(x<0) x=-x,putchar (45);
if(x<10) {
putchar (x+48);
return ;
}
wr(x/10);
putchar (x%10+48);
}
inline int ab (int x) {
if(x<0) return -x;
return x;
}
inline void swap (int &x,int &y) {
x^=y^=x^=y;
}
const int N=10000005;
ll n,m,k,x,id,sum;
bool flag[N],s;
inline ll ksm (ll a,ll b,ll mod) {
ll ans=1;
while (b) {
if(b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
int main () {
r(n),r(m),r(k),r(x);
int now=x;
flag[x]=1;
while (1) {
if(flag[now+m]) break;
now+=m;
if(now>n) now%=n;
flag[now]=1;
sum++;
}
int idd=ksm(10,k,sum+1);
int nowdd=x;
for(int i=1;i<=idd;i++) {
if(nowdd+m<=n) nowdd+=m;
else nowdd=(nowdd+m)%n;
}
wr(nowdd),_v;
return 0;
}