#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<long long,long long>
#define mp make_pair
#define pb push_back
#define WTF puts("wtf")
string s[3];
ll to[26],p[10];
void solve()
{
	cin>>s[0]>>s[1]>>s[2];
	ll cnt=0;
	for(ll i=0;i<3;i++)
	{
		for(ll j=0;j<s[i].size();j++)
		{
			char now=s[i][j];
			if(!to[now-'a']) cnt++,to[now-'a']=cnt;
		}
	}
	if(cnt>10) 
	{
		puts("UNSOLVABLE");
		return;
	}
	else
	{
		for(ll i=1;i<=10;i++) p[i]=i;
		ll n[3];
		do
		{
			n[0]=n[1]=n[2]=0;
			for(ll i=0;i<3;i++) for(ll j=0;j<s[i].size();j++)
			{
				n[i]*=10;
				n[i]+=p[to[s[i][j]-'a']]-1;
			}
			if(p[to[s[0][0]-'a']]>1&&p[to[s[1][0]-'a']]>1&&p[to[s[2][0]-'a']]>1)
			{
				if(n[0]+n[1]==n[2])
				{
					cout<<n[0]<<"\n"<<n[1]<<"\n"<<n[2];
					return;
				}
			}
		}while(next_permutation(p+1,p+11));
		puts("UNSOLVABLE");
		return;
	}
}
signed main()
{
	ll _=1;
	//cin>>_;
	while(_--) solve();
	return 0;
}
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

typedef long long LL;

const int N = 200010;

vector<char> v;
int find(char c)
{
    return lower_bound(v.begin(), v.end(), c) - v.begin();
}

vector<int> g[3];
int num[10];
bool dfs(int u, int state)
{
    if(u == v.size())
    {
        LL x[3] = {0};
        for(int i = 0; i < 3; i ++)
            for(int j : g[i])
                x[i] = x[i] * 10 + num[j];
        
        if(x[0] + x[1] == x[2])
        {
            printf("%lld\n%lld\n%lld\n", x[0], x[1], x[2]);
            return true;
        }
        return false;
    }
    
    for(int i = 0; i < 10; i ++)
        if(!(state >> i & 1))
        {
            if(!i and (g[0][0] == u or g[1][0] == u or g[2][0] == u))  continue;
            num[u] = i;
            if(dfs(u + 1, state | (1 << i)))  return true;
        }
    return false;
}

int main()
{
    string s[3];
    for(int i = 0; i < 3; i ++)
    {
        cin >> s[i];
        for(char c : s[i])  v.push_back(c);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    
    if(v.size() > 10)  return 0 * puts("UNSOLVABLE");
    
    for(int i = 0; i < 3; i ++)
    {
        for(char c : s[i])  g[i].push_back(find(c));
        //for(int j : g[i])  printf("%d ", j);  puts("");
    }
    
    if(!dfs(0, 0))  puts("UNSOLVABLE");
    return 0;
}