#include <bits/stdc++.h>


int count(std::vector<std::vector<int>> vecs) {
    int max = vecs[0][0] - 1;
    int cnt = 0;
    for (int i = 0; i < vecs.size(); i++) {
        if (max < vecs[i][0]) {
            cnt++;
            max = vecs[i][1];
        }
    }
    return cnt;
}


int validation_check(std::vector<std::vector<int>> vecs) {
    std::sort(vecs.begin(), vecs.end(), [] (auto lhs, auto rhs) { return lhs[0] < rhs[0]; });
    int a = count(vecs);
    std::sort(vecs.begin(), vecs.end(), [] (auto lhs, auto rhs) { return lhs[1] < rhs[1]; });
    int b = count(vecs);
    return a - b;
}


std::vector<std::vector<int>> run(int N, int M) {

    std::vector<std::vector<int>> vecs(N, std::vector<int>(2, -1));
     if (M == 0) {
        for (int i = 0; i < N; i++) {
            vecs[i][0] = 2 * i + 1;
            vecs[i][1] = 2 * (i + 1);
        }
    } else if (std::abs(M) > N - 2) {
    } else if (M > 0) {
        vecs[0][0] = 1;
        vecs[0][1] =  2 * (M + 2);
        int i = 1;
        for (;i <= M + 1; i++) {
            vecs[i][0] = 2 * i;
            vecs[i][1] = 2 * i + 1;
        }
        for (; i < N; i++) {
            vecs[i][0] = 2 * i + 1;
            vecs[i][1] = 2 * (i + 1);
        }
    }

    // std::cout << vecs[0][0] << std::endl;
    // if (vecs[0][0] > -1) {
    //     int res = validation_check(vecs);
    //     std::cout << res << " " << M << std::endl;
    //     if (res != M) {
    //         std::cout << "N = " << N << ", M = " << M << std::endl;
    //         for (auto vec : vecs) {
    //             std::cout << vec[0] << " " << vec[1] << std::endl;
    //         }
    //         std::exit(0);
    //     }
    // }
    return vecs;
}


int main() {

    // std::mt19937 gen{std::random_device{}()};
    // std::uniform_int_distribution<> dist(1, 20);
    // for (int i = 0; i < 100; i++) {
    //     int N = dist(gen);
    //     int M = dist(gen) - 10;
    //     run(N, M);
    // }
    int N, M;
    std::cin >> N >> M;
    auto vecs = run(N, M);
    if (vecs[0][0] == -1) {
        std::cout << -1 << std::endl;
    } else {
        for (auto vec : vecs) {
            std::cout << vec[0] << " " << vec[1] << std::endl;
        }
    }
}

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

#define ffor(i, a, b) for (int i = a ; i <= (int) b ; i++) 
#define rfor(i, a, b) for (int i = (int) b ; i >= a ; i--)  

#define vec vector 
#define PB push_back 

#define MP make_pair 
#define MT make_tuple 
#define F first 
#define S second 

using ll = long long int; // watch out for overflows in your code
using pii = pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void debug() { cout << "\n"; };
template <typename T, typename... Targs> 
void debug(T t, Targs... args) {
    cout << t << " ";
    debug(args...);
}

template <typename T1, typename T2> 
inline ostream& operator << (ostream& os, const pair<T1,T2>& p) {
    return os << "(" << p.F << ", " << p.S << ")";
}

template <typename T> 
inline ostream& operator << (ostream& os, const vec<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename T> 
inline ostream& operator << (ostream& os, const vec<vec<T>>& m) {
    for(auto& v : m) {
        for(auto& t : v) {
            os << t << " ";
        }
        os << "\n";
    }
    return os;
}

template <typename T> 
inline ostream& operator << (ostream& os, const set<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename K, typename V> 
inline ostream& operator << (ostream& os, const map<K,V>& m) {
    for(auto& p : m) {
        os << p.F << " -> " << p.S << "\n";
    }
    return os;
}

string s, t, u;
int n;

set<char> ccs;
void consume(const string& S) {
    ffor(i, 0, S.size() - 1) {
        ccs.insert(S[i]);
    }
}

vec<int> m(26, -1);

bool check(const string& S) {
    return m[S[0]-'a'] != 0;
}

ll encode(const string& S) { 
    ll x = 0;
    ffor(i, 0, S.size()-1) {
        x += (ll) m[S[i]-'a'];
        if(i < (int) S.size()-1) {
            x *= 10LL;
        }
    }
    return x;
}

vec<char> ccv;
vec<int> aa;

bool csearch(int i) {
    if(i == n) {
        return check(s) && 
               check(t) && 
               check(u) && 
               encode(s) + encode(t) == encode(u);
    }
    char c = ccv[i];
    //bool ret = false;
    ffor(d, 0, 9) {
        if(aa[d]) {
            aa[d] = 0;
            m[c-'a'] = d;
            if(csearch(i+1)) return true;
            m[c-'a'] = -1;
            aa[d] = 1;
        }
    }
    return false;
}

bool compute() {
    n = (int) ccs.size();
    if(n > 10) return false;
    aa.assign(10, 1);
    for(char c : ccs) ccv.PB(c);
    return csearch(0);
}


////////////////////////////////////////////////////////////////////////

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

    cin >> s >> t >> u;
    consume(s);
    consume(t);
    consume(u);

    bool ans = compute();
    if(ans) {
        cout << encode(s) << "\n";
        cout << encode(t) << "\n";
        cout << encode(u) << "\n";
    }
    else {
        cout << "UNSOLVABLE\n";
    }

    //debug(s, t, u);

    //ffor(i, 0, 25) m[i] = i+1;
    //debug(encode(string("abcdef")));
    //debug(encode("12039"));
    //debug(encode("1293"));
}

