#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define repl(i, n) for (ll i = 0 ; i < n ; i++)
#define Rep(i, n) for (int i = 1 ; i <= n ; i++)
#define Repl(i, n) for (ll i = 1 ; i <= n ; i++)
#define rep3(i, a, n) for (int i = a ; i < n ; i++)
#define pi 3.141592653589793238462643

int main() {
    ios::sync_with_stdio(false);
    ll x, y, a, b, ans = 0; cin >> x >> y >> a >> b;
	while (x < (x + b) / a && x < y / a) {
		x *= a;
		ans++;
	}
	ans += ((y - x) / b);
	if ((y - x) % b == 0) ans--;
	cout << ans;
}


#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

template <typename T>
void print(vector<T>& x) {
    int N = x.size();
    REP(i, N) {
        if (i > 0) cout << " ";
        cout << x[i];
    }
    cout << "\n";
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string _s1, _s2, _s3; cin >> _s1 >> _s2 >> _s3;

    vi s1, s2, s3;
    for (auto &e: _s1) s1.eb(e - 'a');
    for (auto &e: _s2) s2.eb(e - 'a');
    for (auto &e: _s3) s3.eb(e - 'a');

    vi cnt(26, 0);
    for(auto &e: s1) cnt[e] = 1;
    for(auto &e: s2) cnt[e] = 1;
    for(auto &e: s3) cnt[e] = 1;

    if(accumulate(ALL(cnt), 0) > 10) {
        print("UNSOLVABLE");
        return 0;
    }

    vi mid(26, -1);
    int c = 0;
    REP(i, 26) if(cnt[i]) mid[i] = c++;

    vi e = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    do {
        bool f = true;

        ll v1 = 0;
        REP(i, s1.size()) {
            int id = mid[s1[i]];
            int v = e[id];
            if (i == 0 && v == 0) {
                f = false;
                break;
            }

            v1 *= 10;
            v1 += v;
        }

        if (not f) continue;

        ll v2 = 0;
        REP(i, s2.size()) {
            int id = mid[s2[i]];
            int v = e[id];
            if (i == 0 && v == 0) {
                f = false;
                break;
            }

            v2 *= 10;
            v2 += v;
        }

        if (not f) continue;

        ll v3 = 0;
        REP(i, s3.size()) {
            int id = mid[s3[i]];
            int v = e[id];
            if (i == 0 && v == 0) {
                f = false;
                break;
            }

            v3 *= 10;
            v3 += v;
        }

        if (not f) continue;

        if (v1 + v2 == v3) {
            print(v1);
            print(v2);
            print(v3);

            return 0;
        }

    } while(next_permutation(ALL(e)));

    print("UNSOLVABLE");
}
