#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//using namespace boost::multiprecision;
using namespace std;

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(int i=(l);i<int(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(int i=(l);i>=int(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

const int MOD = 1000000007;
//const int MOD = 998244353;

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MAX_N = 200010;

string S1, S2, S3;
const char ng[] = "UNSOLVABLE";
V<> alph_id;
V<> id_alph;
int alph_size = 0;

int StrToNum(V<>& table, const string& s) {
    string ret = "";
    REP(i, s.length()) {
        char c = '0' + table[s[i] - 'a'];
        if(i == 0 && c == '0') { return -1; }
        ret += c;
    }
    return atoll(ret.c_str());
}

signed main() {
    IOS;

    cin >> S1 >> S2 >> S3;

    map<char, bool> pat;
    REP(i, S1.length()) {
        pat[S1[i]] = true;
    }
    REP(i, S2.length()) {
        pat[S2[i]] = true;
    }
    REP(i, S3.length()) {
        pat[S3[i]] = true;
    }

    if(pat.size() > 10) {
        print(ng);
        return 0;
    }

    alph_id.assign(30, -1);
    for(auto& p : pat) {
        alph_id[p.first - 'a'] = alph_size;
        id_alph.pb(p.first - 'a');
        alph_size++;
    }

    V<> num;
    REP(i, 10) {
        num.pb(i);
    }

    do {
        V<> p(30, -1);
        REP(i, alph_size) {
            int ind = id_alph[i];
            p[ind] = num[i];
        }
        int n1 = StrToNum(p, S1);
        if(n1 < 0) { continue; }
        int n2 = StrToNum(p, S2);
        if(n2 < 0) { continue; }
        int n3 = StrToNum(p, S3);
        if(n3 < 0) { continue; }
        if(n1 + n2 == n3) {
            print(n1);
            print(n2);
            print(n3);
            return 0;
        }
    } while(next_permutation(num.begin(), num.end()));
    print(ng);

    return 0;
}

#include<bits/stdc++.h>
 
using namespace std;

typedef long long LL;

int main()
{
   ios_base::sync_with_stdio(0), cin.tie(0);
   
   string s1, s2, s3;

   cin >> s1 >> s2 >> s3;
   
   if(s3.size() < s1.size() || s3.size() < s2.size()){
      cout << "UNSOLVABLE" << '\n';
      return 0;
   }
   vector<int> v(10);
   for(int i=0; i<10; i++) v[i] = i;

   int alpha[26];
   LL n1, n2, n3;
   bool ans = false, flag = false;
   do{
      if(v[0] == 0) continue;

      memset(alpha, -1, sizeof(alpha));
      int cur = 0;
      n1 = n2 = n3 = 0;

      for(int i=0; i<s1.size(); i++){
         n1 *= 10;
         int pos = s1[i] - 'a';
         
         if(alpha[pos] == -1){
            n1 += v[cur];
            alpha[pos] = cur++;
         }
         else
            n1 += v[alpha[pos]];
      }
      if(flag) continue;

      for(int i=0; i<s2.size(); i++){
         n2 *= 10;
         int pos = s2[i] - 'a';
         
         if(alpha[pos] == -1){
            if(cur == 10){
               flag = true;
               break;
            }
            n2 += v[cur];
            alpha[pos] = cur++;
         }
         else
            n2 += v[alpha[pos]];
      }
      if(flag) continue;

      for(int i=0; i<s3.size(); i++){
         n3 *= 10;
         int pos = s3[i] - 'a';
        
         if(alpha[pos] == -1){
            if(cur == 10){
               flag = true;
               break;
            }
            n3 += v[cur];
            alpha[pos] = cur++;
         }
         else
            n3 += v[alpha[pos]];
      }
      if(flag) continue;

      if(n1 == 0 || n2 == 0 || !v[alpha[s1[0]-'a']] || !v[alpha[s2[0]-'a']] || !v[alpha[s3[0]-'a']]) continue;
      if(n1 + n2 == n3){
         ans = true;

         for(int i=0; i<s1.size(); i++){
            int pos = s1[i] - 'a';
            cout << v[alpha[pos]];
         }
         cout << '\n';

         for(int i=0; i<s2.size(); i++){
            int pos = s2[i] - 'a';
            cout << v[alpha[pos]];
         }
         cout << '\n';

         for(int i=0; i<s3.size(); i++){
            int pos = s3[i] - 'a';
            cout << v[alpha[pos]];
         }
         cout << '\n';
         break;
      }

	}while(next_permutation(v.begin(),v.end()));

   if(!ans) cout << "UNSOLVABLE" << '\n';
   return 0;
}