#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/segtree>
// using namespace atcoder;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef priority_queue<pll, vpll, function<bool(pll,pll)> > pqpll; 
typedef priority_queue<ll, vll, function<bool(pll,pll)> > pqll;
 
// struct triplet{ ll fs,sc,td; triplet(ll a,ll b,ll c): fs(a), sc(b), td(c){} };
// typedef priority_queue<triplet, vector<triplet>, function<bool(triplet, triplet)> > pqtri;
// typedef vector<triplet> vtri;
// typedef vector<vtri> vvtri;
 
struct edge{ ll from,to,cost; edge(ll e_from,ll e_to,ll e_cost): from(e_from), to(e_to), cost(e_cost){} };
typedef vector<vector<edge>> Graph;
 
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (1LL << 60)
#define INF (1 << 30)
#define fs first
#define sc second
#define EPS 1e-10
#define ALL(a) a.begin(), a.end()
#define tcheck(a) if((clock() - start)/(ld)CLOCKS_PER_SEC >= a) break
 
template<typename T> ll sz(vector<T> &pos){ return (ll)pos.size(); }
template<typename T> ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); }
template<typename T> ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 
 
void chmin(ll &a, ll b) { if(a > b) a = b; }
void chmax(ll &a, ll b) { if(a < b) a = b; }
 
template<typename T> void chmin(T &a, T b) { if(a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if(a < b) a = b; }
 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
ll dx[4] = {0,-1,1,0},dy[4] = {-1,0,0,1};
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }

bool endflag;

void rec(ll k, vector<string> &s, vb &is_used, vll &num, vector<string> &ans, vb &temp){
    if(26 <= k){
        bool flag = false;
        vll tempnum(3,0);
        rep(i,0,3){
            bool check = true;
            rep(j,0,sz(s[i])){
                if(check && num[s[i][j] - 'a'] == 0){
                    return;
                }
                else check = false;
                tempnum[i] *= 10;
                tempnum[i] += num[s[i][j] - 'a'];
            }
        }
        if(tempnum[0] + tempnum[1] == tempnum[2]){
            endflag = true;
            cout << tempnum[0] << endl;
            cout << tempnum[1] << endl;
            cout << tempnum[2] << endl;
        }
        return;
    }
    else if(!temp[k]){
        rec(k+1,s,is_used,num,ans,temp);
        return;
    }

    if(endflag) return;

    rep(i,0,10){
        if(!is_used[i]){
            is_used[i] = true;
            num[k] = i;
            rec(k+1,s,is_used,num,ans,temp);
            is_used[i] = false;
            num[k] = -1;
        }
    }
    return;
}

int main(){
    vector<string> s(3),ans(3);
    vb temp(26,false);
    ll cnt = 0;
    rep(i,0,3){
        cin >> s[i];
        rep(j,0,sz(s[i])){
            if(temp[s[i][j] - 'a']) cnt++;
            temp[s[i][j] - 'a'] = true;
        }
    }

    vb is_used(10,false);
    vll num(26,-1);
    rep(i,0,3) rep(j,0,sz(s[i])) ans[i].push_back('X');
    rec(0,s,is_used,num,ans,temp);

    if(!endflag) cout << "UNSOLVABLE" << endl;
}
#include <bits/stdc++.h>
using namespace std;
// clang-format off
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint = modint998244353

using ll = int64_t;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& a : v) cin >> a;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<pair<T, T>>& v) {
    for (auto& a : v) cin >> a.first >> a.second;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<tuple<T, T, T>>& v) {
    for (auto& a : v) {
        T a1, a2, a3;
        cin >> a1 >> a2 >> a3;
        a = {a1, a2, a3};
    }
    return is;
}
template<typename T>
istream& operator>>(istream &is, complex<T>& c) {
    double x, y;
    is >> x >> y;
    c.real(x);
    c.imag(y);
    return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
    for (auto& a : v) os << a << " ";
    os << endl;
    return os;
}
template<class T>
bool chmin(T &a, T b) {
    if (a > b) { a = b; return true; } 
    return false;
}
template<class T>
bool chmax(T &a, T b) {
    if (a < b) { a = b; return true; } 
    return false;
}
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define TRC1(a) cout << #a ":" << a
#define TRC2(a, b) TRC1(a); cout << " "; TRC1(b)
#define TRC3(a, b, c) TRC2(a, b); cout << " "; TRC1(c)
#define TRC4(a, b, c, d) TRC3(a, b, c); cout << " "; TRC1(d)
#define GET_NAME(_1,_2,_3,_4,NAME,...) NAME
#define TRC(...) GET_NAME(__VA_ARGS__, TRC4, TRC3, TRC2, TRC1) (__VA_ARGS__) << endl
using veci = vector<int>;
using vecll = vector<ll>;
using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
const int IINF = INT32_MAX;
const ll LINF = INT64_MAX;

// cout << fixed << setprecision(15);
void solve();
int main() { 
    cin.tie(0); ios::sync_with_stdio(0);
    cout << fixed << setprecision(15); solve(); return 0; }
// clang-format on

void solve() {
    vector<string> S(3);
    cin >> S;

    set<char> heads;
    map<char, ll> mp;
    rep(i, 3) {
        ll co = 1;
        if (i == 2) co = -1;
        for_each(rall(S[i]), [&](char c) {
            mp[c] += co;
            co *= 10;
        });
        heads.insert(S[i][0]);
    }
    veci d(10);
    iota(all(d), 0);
    do {
        int i = 0;
        ll tot = 0;
        for (auto [c, co] : mp) {
            if (d[i] == 0 && heads.count(c)) {
                tot = 1;
                break;
            }
            tot += co * d[i++];
        }
        if (tot == 0) {
            i = 0;
            for (auto& [c, co] : mp) co = d[i++];
            rep(j, 3) {
                ll x = 0;
                for (char c : S[j]) x = x * 10 + mp[c];
                cout << x << endl;
            }
            return;
        }
    } while (next_permutation(all(d)));
    cout << "UNSOLVABLE" << endl;
}
