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

void solveCase() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  vector<bool> visit(26);
  for (auto& c : s1) visit[c - 'a'] = 1;
  for (auto& c : s2) visit[c - 'a'] = 1;
  for (auto& c : s3) visit[c - 'a'] = 1;
  vector<int> can;
  for (int k = 0; k < 26; ++k) {
    if (visit[k]) can.push_back(k);
  }
  int SZ = can.size();
  if (SZ > 10) {
    cout << "UNSOLVABLE" << '\n';
    return;
  }
 
  vector<int> p(10), v(26);
  int64_t x, y, z;
  for (int i = 0; i < 10; ++i) p[i] = i;
  bool found = false;
  do {
    for (int i = 0; i < SZ; ++i) v[can[i]] = p[i];
    x = 0, y = 0, z = 0;
    if (v[s1[0] - 'a'] == 0) continue;
    if (v[s2[0] - 'a'] == 0) continue;
    if (v[s3[0] - 'a'] == 0) continue;
    for (auto& c : s1) x = x * 10 + v[c - 'a'];
    for (auto& c : s2) y = y * 10 + v[c - 'a'];
    for (auto& c : s3) z = z * 10 + v[c - 'a'];
    if (x && y && z && x + y == z) {
      found = true;
      break;
    }
  } while (next_permutation(p.begin(), p.end()));
  if (!found) {
    cout << "UNSOLVABLE" << '\n';
  } else {
    cout << x << '\n';
    cout << y << '\n';
    cout << z << '\n';
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int T = 1;
  // cin >> T;
  for (int ti = 1; ti <= T; ++ti) {
    // cout << "Case #" << ti << ": ";
    solveCase();
  }

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

int main() {
    string s[3];
    for (int i = 0; i < 3; i++) cin >> s[i];
    bool c[26] = {};
    vector<char> top;
    for (int i = 0; i < 3; i++) {
        top.push_back(s[i][0]);
        for (int j = 0; j < s[i].length(); j++) c[s[i][j] - 'a'] = true;
    }
    int n = 0;
    int d[26];
    memset(d, -1, sizeof(d));
    int cnt = 0;
    for (int i = 0; i < 26; i++)
        if (c[i]) {
            n++;
            d[i] = cnt;
            cnt++;
        }
    if (n > 10) {
        cout << "UNSOLVABLE" << endl;
        return 0;
    }
    int x[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    do {
        bool topcheck = true;
        for (int i = 0; i < top.size(); i++) {
            if (x[d[top[i] - 'a']] == 0) topcheck = false;
        }
        if (topcheck) {
            long long int m[3] = {};
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < s[i].length(); j++) {
                    m[i] += x[d[s[i][j] - 'a']] * pow(10, s[i].length() - 1 - j);
                }
            }
            if (m[0] + m[1] == m[2]) {
                for (int i = 0; i < 3; i++) {
                    for (int j = 0; j < s[i].length(); j++) {
                        cout << x[d[s[i][j] - 'a']];
                    }
                    cout << endl;
                }
                return 0;
            }
        }
    } while (next_permutation(x, x + 10));
    cout << "UNSOLVABLE" << endl;
}