#include <bits/stdc++.h>
using namespace std;
long long n, m, s, t, res;
int boo[100100], ans[100100];
long long run(long long s, long long t) {
  for (; t; t--)
    if (s && s <= m)
      s = (s + t) % n;
    else
      s = (s - t % n + n) % n;
  return s;
}
int main() {
  scanf("%lld%lld%lld%lld", &n, &m, &s, &t);
  s = run(s, t % n);
  t /= n;
  for (int i = 1; i <= t; i++) {
    boo[s] = i;
    ans[i] = s;
    long long nex = run(s, n);
    if (boo[nex]) {
      res = ans[(t - boo[nex] + 1) % (i - boo[nex] + 1) + boo[nex]];
      break;
    }
    s = nex;
  }
  if (!res) res = s;
  printf("%lld\n", res);
}
