/**
 * @created     : April 11, 2021
 * @handle      : 🇨🇴 @SorKierkegaard
 */

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define finally(value) {cout << (value) << '\n'; return 0;}
#define forn(i, b) for(int i = 0; i < (int) b; ++i)
#define rep(i, a, b) for(int i = int(a); i < (int) b; ++i)
#define trav(x, a) for(auto &x: a)
#define sz(v) ((int) v.size())

using int64 = int64_t;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    const string no = "UNSOLVABLE";

    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    int sz1 = (int) s1.size();
    int sz2 = (int) s2.size();
    int sz3 = (int) s3.size();
    set<char> counter;
    forn(i, sz1) 
        counter.insert(s1[i]);
    forn(i, sz2) 
        counter.insert(s2[i]);
    forn(i, sz3) 
        counter.insert(s3[i]);
    
    if(sz(counter) > 10)
        finally(no)
    int count = (int) counter.size();
    
    map<char, int> letters;
    trav(a, counter)
        letters[a] = 0;
    
    vector<int> perm(10, 0);
    iota(perm.begin(), perm.end(), 0);

    int64 n1, n2, n3;

    function<int64(string&)> to_number = [&](string &s) -> int64 {
        int64 answer = 0LL;
        forn(i, sz(s)) {
            answer *= 10LL;
            answer += int64(letters[s[i]]);
        }
        return answer;
    };

    do {
        int idx = 0;
        trav(ch, letters) {
            ch.second = perm[idx];
            idx++;
        }
        if(letters[s1[0]] == 0 || letters[s2[0]] == 0 || letters[s3[0]] == 0) {
            continue;
        }
        n1 = to_number(s1);
        n2 = to_number(s2);
        n3 = to_number(s3);

        if(n1+n2==n3) {
            cout << n1 << endl;
            cout << n2 << endl;
            cout << n3 << endl;
            return 0;
        }
    } while(next_permutation(perm.begin(), perm.end()));
    
    cout << no << endl;
    
    cout.flush();
    return 0;
}

// THINGS TO KEEP IN MIND
//   * int overflow, time and memory limits
//   * Special case (n = 1?)
//   * Do something instead of nothing and stay organized
//   * Don't get stuck in one approach

// TIME AND MEMORY LIMITS
//   * 1 second is approximately 10^8 operations (c++)
//   * 10^6 Elements of 32 Bit (4 bytes) is equal to 4 MB
//   * 62x10^6 Elements of 32 Bit (4 bytes) is equal to 250 MB
//   * 10^6 Elements of 64 Bits (8 bytes) is equal to 8 MB
//   * 31x10^6 Elements of 64 Bit (8 bytes) is equal to 250 MB
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;
ll a[10];
vector <ll> v;
string s[3];
bool ok = false;
ll val[26];

void heapPermutation(ll a[], ll size, ll n) {
	if (ok) return;
	if (size == 1) {
		//printArr(a, n);
		ll u[3] = {0};
		for (ll i = 0; i < sz(v); i++) {
			val[v[i]] = a[i];
		}
		bool np = true;
		for (ll i = 0; i < 3; i++) {
			ll x = 1;
			for (ll j = s[i].length() - 1; j >= 0; j--) {
				if (j == 0 && val[s[i][j] - 'a'] == 0) np = false;
				u[i] += (val[s[i][j] - 'a']) * x;
				x *= 10;
			}
		}
		if (np && u[0] + u[1] == u[2] && u[0] > 0 && u[1] > 0) {
			cout << u[0] << '\n';
			cout << u[1] << '\n';
			cout << u[2] << '\n';
			ok = true;
		}
		return;
	}

	for (ll i = 0; i < size; i++) {
		heapPermutation(a, size - 1, n);
		if (size % 2 == 1)
			swap(a[0], a[size - 1]);
		else
			swap(a[i], a[size - 1]);
	}
}

void solve () {
	for (ll i = 0; i < 10; i++) {
		a[i] = i;
	}
	for (ll i = 0; i < 3; i++) {
		cin >> s[i];
	}
	set <ll> st;
	for (ll i = 0; i < 3; i++) {
		for (ll j = 0; j < s[i].length(); j++) {
			st.insert(s[i][j] - 'a');
		}
	}
	if (sz(st) > 10) {
		cout << "UNSOLVABLE\n";
		return;
	}
	for (ll i : st) {
		v.pb(i);
	}
	heapPermutation(a, 10, 10);
	if (!ok) {
		cout << "UNSOLVABLE\n";
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
  #endif
	int t = 1;
	while (t--) {
		solve();
	}
 	return 0;
}