#include<bits/stdc++.h> #define int long long usingnamespacestd;
int n, m, k, x; intksm(int a, int b) { int res = 1; while (b) { if (b & 1) res = res * a % n; a = a * a % n; b >>= 1; } return res; } signedmain() { cin >> n >> m >> k >> x; cout << (x % n + m % n * ksm(10, k) % n) % n; return0; }