// D - Send More Money
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define vec vector
#define rep(i,e) for(int i=0;i<(e);++i)
#define sz(a) int(a.size())

ll INF = 1e18;
string in(){ string s; cin>>s; return s; }
vec<int> reversed(vec<int> s){ reverse(s.begin(), s.end()); return s; }

vec<vec<int>> S(3);
vec<ll> A(26, INF), sign{1, 1, -1};
vec<int> C;
vec<ll> ans(3);

bool dfs(set<int>&t, string P){
	if(sz(P) == sz(C)){
		ll tot = 0;
		rep(i, sz(C)){
			if(P[i] == '0')
				for(auto&s:S) if(s[0] == C[i]) return false;
			tot += (P[i]-'0') * A[C[i]];
		}
		if(tot) return false;

		rep(i, sz(C)) A[C[i]] = P[i]-'0';
		rep(i, 3) for(auto&c:S[i]) ans[i] = ans[i]*10 + A[c];
		return true;
	}

	set<int> u = t;
	for(auto&x:t){
		u.erase(x);
		if(dfs(u, P + to_string(x))) return true;
		u.insert(x);
	}
	return false;
}

int main(){
	rep(i, 3){
		for(auto&c:in()) S[i].push_back(c-'a');
		int w = 1;
		for(auto&c:reversed(S[i])){
			if(A[c] == INF){
				A[c] = 0;
				C.push_back(c);
			}
			A[c] += sign[i] * w;
			w *= 10;
		}
	}

	if(sz(C) > 10){ puts("UNSOLVABLE"); return 0; }

	set<int> t{0,1,2,3,4,5,6,7,8,9};
	if(dfs(t, "")) for(auto&x:ans) cout<< x <<endl;
	else puts("UNSOLVABLE");
}

#include <bits/stdc++.h>
#include <unordered_set>
#include <cmath>
#include <algorithm>

// URL: https://atcoder.jp/contests/abc198/tasks/abc198_d

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n)? "YES": "NO") << endl
#define Yes(n) cout << ((n)? "Yes": "No") << endl

#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fore(x, a) for(auto& (x) : (a))

#define FORL(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define repll(i, n) for (ll i = 0; i < (ll)(n); i++)

#define ALL(a) (a).begin(), (a).end()

#define VECCIN(x) for(auto& youso_: (x)) cin >> youso_
#define VECCOUT(x) for(auto& youso_: (x)) cout << youso_ << " ";cout << endl

#define pb push_back
#define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll INFL = numeric_limits<ll>::max() / 4;
const int INF = 1e9;
const int MOD = 1e9 + 7;

string S1, S2, S3;
vector<char> chars;
char used[10] = {0};

// ll pow10(int n){
//   ll ans = 1;
//   rep(i, n) ans *= 10;
//   return ans;
// }

bool check() {
  map<char, char> mp;
  rep(i, 10){
    if(used[i] != 0) mp[used[i]] = char('0' + i);
  }
  string SS1, SS2, SS3;
  fore(c, S1) SS1 += mp[c];
  fore(c, S2) SS2 += mp[c];
  fore(c, S3) SS3 += mp[c];

   if(to_string(stoll(SS1)) != SS1) return false;
  if(to_string(stoll(SS2)) != SS2) return false;
  if(to_string(stoll(SS3)) != SS3) return false;
  if(stoll(SS1) + stoll(SS2) != stoll(SS3)) return false;
  if(stoll(SS1) == 0) return false;
  if(stoll(SS2) == 0) return false;
  if(stoll(SS3) == 0) return false;

  cout << SS1 << endl;
  cout << SS2 << endl;
  cout << SS3 << endl;

  return true;
}

bool dfs(int cn){
  if(cn == chars.size()) return check();

  rep(i, 10) if(used[i] == 0){
    used[i] = chars[cn];
    if(dfs(cn + 1)) return true;
    used[i] = 0;
  }

  return false;
}

int main(){
  optimize_cin();

  cin >> S1 >> S2 >> S3;
  fore(a, S1) chars.pb(a);
  fore(a, S2) chars.pb(a);
  fore(a, S3) chars.pb(a);

  sort(ALL(chars));
  chars.erase(unique(ALL(chars)), chars.end());

  if(chars.size() > 10) {
    cout << "UNSOLVABLE" << endl;
    return 0;
  }
  // dump(chars.size());

  bool res = dfs(0);
  if(res == false) cout << "UNSOLVABLE" << endl;


  // cout << pow10(0) << endl;



  return 0;
}