#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; #define REP(i,n) for(ll i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;}; template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;}; constexpr ll MOD=1000000007; constexpr ll INF=2e18; int main(){ ll p, q, x, y; cin >> p >> q >> x >> y; string ans; ll n; for(ll i=0;1;i++){ if((q*i+y)%10==0) continue; ans=to_string(q*i+y); reverse(ALL(ans)); n=0; REP(j,(int)ans.size()){ n=n*10%p; n=(n+ans[j]-'0')%p; } if(n!=0) break; if(n==x) break; } while(n!=x){ n=n*10%p; ans+='0'; } cout << ans << endl; return 0; }