#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

ll powe(ll a, ll b){//aのb乗のmod
    ll ret = 1;
    while(0 < b){
        if((b%2) == 0){
            a = (a*a);
            b >>= 1;
        }
        else{
            ret = (ret*a);
            b--;
        }
    }
    return ret;
}

int main(){
    string s, t, u; cin >> s >> t >> u;
    vector<ll> cl(26,0);
    vector<ll> hl(26,0);
    REP(i,s.length()) {
        if (i==0) hl[s[i]-'a']=1;
        cl[s[i]-'a']=1;
    }
    REP(i,t.length()) {
        if (i==0) hl[t[i]-'a']=1;
        cl[t[i]-'a']=1;
    }
    REP(i,u.length()) {
        if (i==0) hl[u[i]-'a']=1;
        cl[u[i]-'a']=1;
    }
    ll cnter = 0;
    REP(i,26) if (cl[i]==1) cnter++;
    if (cnter>10) {
        cout << "UNSOLVABLE" << endl;
        return 0;
    }
    ll ind = 0;
    REP(i,26) {
        if (cl[i]) {
            cl[i]=ind;
            ind++;
        }
        else {
            cl[i]=-1;
        }
    }
    vector<ll> keisu(26,0);
    ll ss = s.length(); ll tt = t.length(); ll uu = u.length();
    REP(i,s.length()) keisu[s[i]-'a']+=powe(10,ss-1-i);
    REP(i,t.length()) keisu[t[i]-'a']+=powe(10,tt-1-i);
    REP(i,u.length()) keisu[u[i]-'a']-=powe(10,uu-1-i);
    vector<ll> digits = {0,1,2,3,4,5,6,7,8,9};
    do {
        ll val = 0;
        bool jud = true;
        REP(i,26){
            if (hl[i]==1 && digits[cl[i]]==0) jud = false;
        }
        if (jud==false) continue;
        REP(i,26) {
            if (cl[i]==-1) continue;
            val+=digits[cl[i]]*keisu[i];
        }
        if (val==0) {
            // REP(i,26) cout << keisu[i] << " ";
            // cout << endl;
            // REP(i,26) cout << cl[i] << " ";
            // cout << endl;
            // REP(i,26) cout << digits[cl[i]] << " ";
            // cout << endl;
            // REP(i,26) cout << hl[i] << " ";
            // cout << endl;
            vector<char> charl(26,'0');
            REP(i,26) {
                if (cl[i]!=-1) charl[i]+=digits[cl[i]];
            }
            REP(i,ss) s[i]=charl[s[i]-'a'];
            REP(i,tt) t[i]=charl[t[i]-'a'];
            REP(i,uu) u[i]=charl[u[i]-'a'];
            cout << s << endl;
            cout << t << endl;
            cout << u << endl;
            return 0;
        }
    } while (next_permutation(digits.begin(),digits.end()));
    cout << "UNSOLVABLE" << endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define REP(a,b) for(long long a = 0;a < b;++a)
using ld = long double;
unsigned long xor128() {
  static unsigned long x=time(NULL), y=362436069, z=521288629, w=88675123;
  unsigned long t=(x^(x<<11));
  x=y; y=z; z=w;
  return ( w=(w^(w>>19))^(t^(t>>8)) );
}


typedef struct Sponsor{
    int x;
    int y;
    int area;
} Sponsor;
typedef struct AD{
    int x;
    int y;
    int dx;
    int dy;
    Sponsor sponsor;
} AD;

inline bool check_intersect(AD a,AD b){
    bool ans = (min(a.x,b.x) <= max(a.x,b.x) and max(a.x,b.x) < min(a.x+a.dx,b.x + b.dx));
    ans &= (min(a.y,b.y) <= max(a.y,b.y) and max(a.y,b.y) < min(a.y+a.dy,b.y + b.dy));
    return ans;
}
bool validate(vector<AD> inputs){
    for(int i = 0;i < inputs.size();++i){
        if(inputs[i].x + inputs[i].dx > 10000 or inputs[i].y + inputs[i].dy > 10000) return false;
        for(int q = i+1;q < inputs.size();++q){
            if(check_intersect(inputs[i],inputs[q]) == true) return false;
        }
    }
    return true;
}
ld scoring(vector<AD> inputs,ld border){
    ld ans = 0;
    for(int i = 0;i < inputs.size();++i){
        if(inputs[i].x <= inputs[i].sponsor.x and inputs[i].sponsor.x < inputs[i].x + inputs[i].dx
            and inputs[i].y <= inputs[i].sponsor.y and inputs[i].sponsor.y < inputs[i].y + inputs[i].dy){
                ld real_area = inputs[i].dx * inputs[i].dy;
                ld expected_area = inputs[i].sponsor.area;
                ans += 1.0L - abs(border - pow(1 - min(real_area,expected_area)/max(real_area,expected_area),2.0));
            }else return -1;
    }
    ans /= (ld)inputs.size();
    return ans;
}

int main(){
    int n;
    cin >> n;
    vector<AD> inputs;
    REP(i,n){
        int a,b,c;
        cin >> a >> b >> c;
        inputs.push_back(AD{a,b,1,1,Sponsor{a,b,c}});
    }
    ld now_score = scoring(inputs,0);
    for(int i = 0;i < 3000000;++i){
        int target = xor128() % inputs.size();
        AD tmp = inputs[target];
        int dir = xor128() % 8;
        if(i % 20000 != 0){
            if(dir == 0){
                inputs[target].dx += 1;
            }else if(dir == 1){
                inputs[target].dy += 1;
            }else if(dir == 2){
                inputs[target].x -= 1;
                inputs[target].dx += 1;
            }else if(dir == 3){
                inputs[target].y -= 1;
                inputs[target].dy += 1;
            }else if(dir == 4){
                inputs[target].x += 1;
            }else if(dir == 5){
                inputs[target].y += 1;
            }else if(dir == 6){
                inputs[target].x -= 1;
            }else if(dir == 7){
                inputs[target].y -= 1;
            }
        }
        bool ok = true;
        for(int q = 0;q < inputs.size();++q){
            if(q != target and check_intersect(inputs[q],inputs[target]) == true){
                ok = false;
            }
        }
        if(inputs[target].dx <= 0 or inputs[target].dy <= 0 or inputs[target].x < 0 or inputs[target].y < 0) ok = false;
        if(inputs[target].x + inputs[target].dx > 10000 or inputs[target].y + inputs[target].dy > 10000) ok = false;
        ld score = 0;
        int hoge = (ld)(3000000.0 - i) / 300000.0;
        ld prob = hoge / 10.0;
        prob *= prob;
        score = scoring(inputs,prob) + (1.00L - prob);
        if(ok and score >= now_score){
            now_score = score;
        }else{
            inputs[target] = tmp;
        }
    }
    for(int i = 0;i < n;++i){
        cout << inputs[i].x << " " << inputs[i].y << " " << inputs[i].x + inputs[i].dx << " " << inputs[i].y + inputs[i].dy << endl;
    }
}