#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int n,m;
string s[15];
int sz;
bool not_front[10];
ll res=0;
vector<int> VV;

void cal(){
	vector<int> v=VV;
	do{
		bool ok=true;
		for(int i=0;i<m;i++){
			if(v[i]==0 and !not_front[i])ok=false;
		}
		if(!ok)continue;
		int k=0;
		for(int j=0;j<sz;j++){
			int sum=k/10;
			for(int i=0;i<n-1;i++){
				if((int)s[i].size()>j){
					sum+=v[s[i][j]-'A'];
				}
			}
			if(sum>0 and (int)(s[n-1].size())<=j){
				ok=false; break;
			}
			if(v[s[n-1][j]-'A']!=sum%10){
				ok=false; break;
			}
			k=sum;
		}
		if(ok and k/10==0){
			for(int i=0;i<n;i++){
				reverse(s[i].begin(), s[i].end());
				for(int j=0;j<s[i].size();j++){
					cout << v[s[i][j]-'A'];
				}
				cout << endl;
				// cout << s[i] << endl;
			}
			exit(0);
		}
	}while(next_permutation(v.begin(), v.end()));
}

void solve(int sz,int cur){
	if(sz==m){
		cal(); return;
	}
	if(cur==10)return;
	VV.push_back(cur);
	solve(sz+1,cur+1);
	VV.pop_back();
	solve(sz,cur+1);
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    n=3;
    vector<char> V;
	for(int i=0;i<n;i++){
		cin >> s[i];
		for(int j=0;j<s[i].size();j++){
			s[i][j]+=(+'A'-'a');
		}
		for(char c:s[i]){
			V.push_back(c);
		}
	}
	sort(V.begin(), V.end());
	V.erase(unique(V.begin(), V.end()),V.end());
	for(int i=0;i<n;i++){
		for(int j=0;j<s[i].size();j++){
			s[i][j]='A'+(lower_bound(V.begin(), V.end(),s[i][j])-V.begin());
		}
	}
	// leading-0対策
	m=V.size();
	for(int i=0;i<m;i++){
		not_front[i]=true;
	}
	sz=0;
	for(int i=0;i<n;i++){
		if((int)s[i].size())not_front[s[i][0]-'A']=false;
		reverse(s[i].begin(), s[i].end());
		sz=max(sz,(int)(s[i].size()));
	}
	// ここから　書く
	res=0;
	solve(0,0);
	cout << "UNSOLVABLE" << endl;
}
//#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;


#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 +7; const ll INF = 1e18;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

//using mint = atcoder::modint998244353;

bool f(string s1, string s2, string s3){

	VI cv(128, -1); int ct=0;
	for(auto ch: (s1+s2+s3)) if(cv[ch]==-1) cv[ch] = ct++;
	if(ct>10){/*cerr<<s1+" "+s2+" "+s3+" over 11!!! \n";*/return false;}
	vector<VI> v(3);

	for(auto ch: s1) v[0].push_back(cv[ch]);
	for(auto ch: s2) v[1].push_back(cv[ch]);
	for(auto ch: s3) v[2].push_back(cv[ch]);

	//for(auto xl: v){for(auto x :xl) cerr<<x<<" ";dbg();}

	
	rep(msk, 1<<10){ // ncr(10, ct) * ct! <= 10!
		VI seq;
		if(__builtin_popcount(msk) != ct) continue;
		rep(i, 10) if(msk>>i &1) seq.push_back(i);
		//for(auto x :seq) cerr<<x<<" "; dbg();
		do {
			bool ok =1;
			VL nv(3);
			rep(i, 3){
				if(seq[v[i][0]]==0){ ok=0; break;} //先頭0 対策
				for(auto ch: v[i]) nv[i] = nv[i] *10 + seq[ch];
			}
			if(ok && nv[0] + nv[1] == nv[2]){
				cout << nv[0] <<"\n";
				cout << nv[1] <<"\n";
				cout << nv[2] <<"\n";
				//for(auto x :seq) cerr<<x<<" "; dbg("OK");
				return true;
				//if(sz(cnd) > 1) return false; //複数解 認めない場合
			}
		} while ( next_permutation(all(seq)) );
	}
	 return false;
}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	vector<string> v(3);
	rep(i, 3) cin >>v[i];
	
	auto zz= f(v[0], v[1],v[2]);
	
	if(!zz) cout << "UNSOLVABLE"  <<"\n";
	return 0;
}
