#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define sz(x) int(x.size())
#define pcnt __builtin_popcountll
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template <typename T> void print(T a) {cout << a << ' ';}
template <typename T> void printe(T a) {cout << a << endl;}
template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;}
template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
template <typename T> using vc = vector<T>;
template <typename T> using vv = vc<vc<T>>;
template <typename T> using vvv = vc<vv<T>>;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vvl = vv<ll>;
vi di = {-1, 1,  0, 0, -1, -1,  1, 1};
vi dj = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    vc<string> s(3);
    rep(i, 3) cin >> s[i];
    map<char, ll> Mp; // その文字に割り当てられたものを何倍するか
    rep(i, 3) {
        ll scale = 1;
        for (int j = sz(s[i])-1; j >= 0; j--) {
            if (i == 2) {
                Mp[s[i][j]] -= scale;
            }
            else {
                Mp[s[i][j]] += scale;
            }
            scale *= 10;
        }
    }
    if (sz(Mp) > 10) {
        cout << "UNSOLVABLE" << endl;
        return 0;
    }
    
    map<char, int> Mp2; // 各文字に何の文字入れるか
    auto restore = [&] (string t) {
        ll res = 0;
        rep(i, sz(t)) {
            res *= 10;
            res += Mp2[t[i]];
        }
        return res;
    };
    vi p(10);
    rep(i, 10) p[i] = i;
    do {
        int now = 0; // 今何番目の要素か
        ll sum = 0;
        for (auto x : Mp) {
            sum += p[now] * x.second;
            Mp2[x.first] = p[now];
            now++;
        }
        if (sum == 0) {
            vl n(3);
            bool flag = true;
            rep(i, 3) {
                n[i] = restore(s[i]);
                if (n[i] <= 0 || sz(to_string(n[i])) < sz(s[i])) flag = false;
            }
            if (flag) {
                rep(i, 3) cout << n[i] << endl;
                return 0;
            }
            else {
                continue;
            }
        }
        Mp2.clear();
    } while (next_permutation(all(p)));

    cout << "UNSOLVABLE" << endl;
    
    return 0;
}
/*                             हरे कृष्ण हरे कृष्ण कृष्ण कृष्ण हरे हरे
                                  हरे राम हरे राम राम राम हरे हरे                                     */
#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define pob pop_back
typedef long long int lli;
#define test lli t; cin>>t; while(t--)
#define ff first
#define ss second
#define F(n) for(lli i=0;i<n;i++)
#define pf pop_front
#define lb lower_bound
#define ub upper_bound
#define setbits(x)  __builtin_popcountll(x)
#define zerobits(x)  __builtin_ctzll(x)
#define bs binary_search
#define all(x) x.begin(),x.end()
#define nl "\n"
#define loop(i,s,n) for(lli i=s;i<n;i++)
#define pp(a)  for(auto x : a)  cout<<x<<" ";  cout<<nl;
#define mem(arr,x) memset(arr,x,sizeof(arr))
#define mod 1000000007
#define inf 1e18
#define tt(n) cin>>n; lli a[n]; loop(i,0,n) cin>>a[i];
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ps(x,y) fixed<<setprecision(y)<<x

int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
     lli n,i;
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    set<char> s;
    loop(i,0,s1.length()) s.insert(s1[i]);
    loop(i,0,s2.length()) s.insert(s2[i]);
    loop(i,0,s3.length()) s.insert(s3[i]);
    if(s.size()>10) cout<<"UNSOLVABLE";
    else
    {
        std::vector<char> a;
        n=s.size();
        for(auto x: s) a.pb(x);
        lli b[10]={0,1,2,3,4,5,6,7,8,9},f=0;
        //for(auto x: a) cout<<x<<" ";
        //set<lli> sm;
        do
        {
            map<char,lli> m;
            lli k=0;
            loop(i,0,n) m[a[i]]=b[k++];
            //for(auto x: m) cout<<x.ff<<" "<<x.ss<<nl;
              //  break;
            //sm.insert(m['s']);
            lli c1=0,c2=0,c3=0;
            if(m[s1[0]]==0 || m[s2[0]]==0 || m[s3[0]]==0) ;
            else
            {
                loop(i,0,s1.length()) 
                {
                    c1=(c1*10)+m[s1[i]];
                }
                loop(i,0,s2.length()) 
                {
                    c2=(c2*10)+m[s2[i]];
                }
                loop(i,0,s3.length()) 
                {
                    c3=(c3*10)+m[s3[i]];
                }
                if(c1+c2==c3 && c1>0 && c2>0 && c3>0)
                {
                    f=1;
                    loop(i,0,s1.length()) cout<<m[s1[i]];
                    cout<<nl;
                    loop(i,0,s2.length()) cout<<m[s2[i]];
                    cout<<nl;
                    loop(i,0,s3.length()) cout<<m[s3[i]];
                    break;
                }
            }
        }while(next_permutation(b,b+10));
        //for(auto x: sm) cout<<x<<" ";
        if(f==0) cout<<"UNSOLVABLE";
    }
return 0;
}