#include<bits/stdc++.h>
#include<unordered_map>
#define sz(s) (int)s.size()
#define all(s) s.begin(),s.end()
using namespace std;
typedef long long ll;
void fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}
bool valid(ll n, string s)
{
	if (!n)
		return 0;
	int c = 0;
	while (n)
	{
		c++;
		n /= 10;
	}
	return c == sz(s);
}
void Men7a()
{
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	set<char>st;
	for (int i = 0; i < sz(s1); i++)
		st.insert(s1[i]);
	for (int i = 0; i < sz(s2); i++)
		st.insert(s2[i]);
	for (int i = 0; i < sz(s3); i++)
		st.insert(s3[i]);
	if (sz(st)>10)
	{
		cout << "UNSOLVABLE\n";
		return;
	}
	unordered_map<char, int>mp;
	vector<int>v = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	do
	{
		for (auto x : st)
			mp[x] = -1;
		int ix = 0;
		for (auto x : st)
				mp[x] = v[ix++];
		ll a = 0, b = 0, c = 0;
		for (int i = 0; i < sz(s1); i++)
		{
			a *= 10;
			a += mp[s1[i]];
		}
		for (int i = 0; i < sz(s2); i++)
		{
			b *= 10;
			b += mp[s2[i]];
		}
		for (int i = 0; i < sz(s3); i++)
		{
			c *= 10;
			c += mp[s3[i]];
		}
		if (a + b == c && valid(a, s1) && valid(b, s2) && valid(c, s3))
		{
			cout << a << "\n" << b << "\n" << c << "\n";
			return;
		}
	} while (next_permutation(all(v)));
	cout << "UNSOLVABLE\n";
}
int main()
{
	fast();
	int test_case = 1;
	//freopen("","r",stdin);
	//cin >> test_case;
	while (test_case--)
		Men7a();
}
// 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; }

int main(){
	vec<vec<int>> S(3);
	vec<ll> A(26, INF), sign{1, 1, -1};
	set<int> C;
	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;
			A[c] += sign[i] * w;
			C.insert(c);
			w *= 10;
		}
	}

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

	vec<int> P(10); iota(P.begin(), P.end(), 0);
	do{
		ll tot = 0;
		auto pos_p = P.begin();
		rep(c, sz(A)){
			if(A[c] == INF) continue;
			if(*pos_p == 0)
				for(auto&s:S) if(s[0] == c){ tot = INF; break; }
			tot += *pos_p * A[c];
			pos_p++;
		}
		if(tot) continue;

		pos_p = P.begin();
		rep(c, sz(A)) if(A[c] != INF) A[c] = *pos_p++;
		for(auto&s:S){
			ll ans = 0;
			for(auto&c:s) ans = ans*10 + A[c];
			cout<< ans <<endl;
		}
		return 0;
	}while(next_permutation(P.begin(), P.end()));

	puts("UNSOLVABLE");
}
