#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    int table[10][10][10][10];

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    table[i][j][x][y] = -2;
                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res;
                    if(table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] != -2) {
                        res = table[(int) a[k] - 48][(int) a[k + 1] - 48][i][j];
                    }
                    else {
                        res = bfs(i, j, (int)a[k] - 48, (int)a[k+1] - 48);
                        table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] = res;
                    }

                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += (res-1);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    int table[10][10][10][10];

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    table[i][j][x][y] = -2;
                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res;

                    if(table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] != -2) {
                        res = table[(int)a[k] - 48][(int)a[k+1] - 48][i][j];
                    }
                    else {
                        res = bfs(i, j, get_int(a[k]), get_int(a[k+1]));
                        table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] = res;
                    }

                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += (res-1);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int src, int tar) {
//    cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    bool visited[10] = {0};
    q.push({src, 0});

    while (!q.empty()) {
        Node curr = q.front();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

//        if (curr.val % 10 == tar) {
//            return curr.dist - 1;
//        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

        if(i_d == tar || j_d == tar) {
            return curr.dist;
        }
//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visited[i_d]) {
            q.push({i_d, curr.dist + 1});
            visited[i_d] = true;
        }
        if(!visited[j_d]) {
            q.push({j_d, curr.dist + 1});
            visited[j_d] = true;
        }

        q.pop();
    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    int table[10][10][10][10];

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    table[i][j][x][y] = -2;
                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res;
                    if(table[get_int(a[k])][get_int(a[k+1])][i][j] != -2) {
                        res = table[get_int(a[k])][get_int(a[k+1])][i][j];
                    }
                    else {
                        res = bfs(i, j, get_int(a[k]), get_int(a[k+1]));
                        table[get_int(a[k])][get_int(a[k+1])][i][j] = res;
                    }

                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += (res);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    int table[10][10][10][10];

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    table[i][j][x][y] = -2;
                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res;

                    if(table[get_int(a[k])][get_int(a[k+1])][i][j] != -2) {
                        res = table[get_int(a[k])][get_int(a[k+1])][i][j];
                    }
                    else {
                        res = bfs(i, j, get_int(a[k]), get_int(a[k+1]));
                        table[get_int(a[k])][get_int(a[k+1])][i][j] = res;
                    }

                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += (res-1);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int shortest(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
//    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val == tar) {
            return curr.dist - 1;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int table[10][10][10][10];

int minimumMissing(int i, int j, string &a) {
    int r = 0;
    for (int k = 1; k < a.size(); k++) {

//                    int res = shortest(i, j, get_int(a[k]), get_int(a[k + 1]));
        int res = table[(int)a[k-1] - 48][(int)a[k] - 48][i][j];
        if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
            r = -1;
            break;
        }
        r += (res);
    }
    return r;
}

int main() {

    string a;
    cin >> a;

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    int r = bfs(x, y, i, j);
                    table[i][j][x][y] = r;
                    table[i][j][y][x] = r;
                }
            }
        }
    }

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = i; j < 10; j++) {
            int r = minimumMissing(i, j, a);
            rr[i][j] = r;
            rr[j][i] = r;
        }
    }

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            cout << rr[i][j] << " ";
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            for(int x = 0; x < 10; x++) {
//                for(int y = 0; y < 10; y++) {
//                    int r1 = shortest(x, y, i, j);
//                    int r2 = bfs(x, y, i, j);
//
//                    cout << r1 << " " << r2;
//                    if(r1 != r2) cout << "GRESKA";
//
//                    cout << endl;
//                }
//            }
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int shortest(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val == tar) {
            return curr.dist;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int table[10][10][10][10];

int minimumMissing(int i, int j, string &a) {
    int r = 0;
    for (int k = 1; k < a.size(); k++) {

//                    int res = shortest(i, j, get_int(a[k]), get_int(a[k + 1]));
        int res = table[get_int(a[k-1])][get_int(a[k])][i][j];
        if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
            r = -1;
            break;
        }
        r += (res-1);
    }
    return r;
}

int main() {

    string a;
    cin >> a;

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    int r = shortest(x, y, i, j);
                    table[i][j][x][y] = r;
                    table[i][j][y][x] = r;
                }
            }
        }
    }

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = i; j < 10; j++) {
           int r = minimumMissing(i, j, a);
            rr[i][j] = r;
            rr[j][i] = r;
        }
    }

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            cout << rr[i][j] << " ";
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            for(int x = 0; x < 10; x++) {
//                for(int y = 0; y < 10; y++) {
//                    int r1 = shortest(x, y, i, j);
//                    int r2 = bfs(x, y, i, j);
//
//                    cout << r1 << " " << r2;
//                    if(r1 != r2) cout << "GRESKA";
//
//                    cout << endl;
//                }
//            }
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    int table[10][10][10][10];

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    table[i][j][x][y] = -2;
                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res;

                    if(table[get_int(a[k])][get_int(a[k+1])][i][j] != -2) {
                        res = table[(int) a[k] - 48][(int) a[k + 1] - 48][i][j];
                    }
                    else {
                        res = bfs(i, j, get_int(a[k]), get_int(a[k+1]));
                        table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] = res;
                    }

                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += (res-1);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int shortest(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
//    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val == tar) {
            return curr.dist;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int table[10][10][10][10];

int minimumMissing(int i, int j, string &a) {
    int r = 0;
    for (int k = 1; k < a.size(); k++) {

//                    int res = shortest(i, j, get_int(a[k]), get_int(a[k + 1]));
        int res = table[(int)a[k-1] - 48][(int)a[k] - 48][i][j];
        if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
            r = -1;
            break;
        }
        r += (res-1);
    }
    return r;
}

int main() {

    string a;
    cin >> a;

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    int r = bfs(x, y, i, j);
                    table[i][j][x][y] = r;
                    table[i][j][y][x] = r;
                }
            }
        }
    }

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = i; j < 10; j++) {
            int r = minimumMissing(i, j, a);
            rr[i][j] = r;
            rr[j][i] = r;
        }
    }

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            cout << rr[i][j] << " ";
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            for(int x = 0; x < 10; x++) {
//                for(int y = 0; y < 10; y++) {
//                    int r1 = shortest(x, y, i, j);
//                    int r2 = bfs(x, y, i, j);
//
//                    cout << r1 << " " << r2;
//                    if(r1 != r2) cout << "GRESKA";
//
//                    cout << endl;
//                }
//            }
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    return c - '0';
}

int bfs(int i, int j, int src, int tar) {

    queue<Node> q;
    bool visited[10] = {0};
    q.push({src, 0});
    visited[src] = true;
    while (!q.empty()) {
        Node curr = q.front();

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

        if (i_d == tar || j_d == tar) {
            return curr.dist;
        }
        if (!visited[i_d]) {
            q.push({i_d, curr.dist + 1});
            visited[i_d] = true;
        }
        if (!visited[j_d]) {
            q.push({j_d, curr.dist + 1});
            visited[j_d] = true;
        }

        q.pop();
    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            int r = 0;
            for (int k = 0; k < a.size() - 1; k++) {
                int res = bfs(i, j, get_int(a[k]), get_int(a[k + 1]));

                if (res == -1) {
                    r = -1;
                    break;
                }
                r += (res);
            }

            cout << r << " ";
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val % 10 == tar) {
//            if(curr.dist == 0) return curr.dist;
            return curr.dist - 1;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res = bfs(i, j, get_int(a[k]), get_int(a[k + 1]));
                    if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
                        r = -1;
                        break;
                    }
                    r += res;
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            int r = bfs()
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int shortest(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val == tar) {
            return curr.dist;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int table[10][10][10][10];
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    int r = shortest(x, y, i, j);
                    table[i][j][x][y] = r;
                    table[i][j][y][x] = r;
                }
            }
        }
    }

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 1; k < a.size(); k++) {

//                    int res = shortest(i, j, get_int(a[k]), get_int(a[k + 1]));
                    int res = table[get_int(a[k-1])][get_int(a[k])][i][j];
                    if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
                        r = -1;
                        break;
                    }
                    r += (res-1);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            for(int x = 0; x < 10; x++) {
//                for(int y = 0; y < 10; y++) {
//                    int r1 = shortest(x, y, i, j);
//                    int r2 = bfs(x, y, i, j);
//
//                    cout << r1 << " " << r2;
//                    if(r1 != r2) cout << "GRESKA";
//
//                    cout << endl;
//                }
//            }
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int shortest(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val == tar) {
            return curr.dist;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int table[10][10][10][10];
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    int r = shortest(x, y, i, j);
                    table[i][j][x][y] = r;
                    table[i][j][y][x] = r;
                }
            }
        }
    }

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = i; j < 10; j++) {
            if (rr[i][j] != -2) {
//                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 1; k < a.size(); k++) {

//                    int res = shortest(i, j, get_int(a[k]), get_int(a[k + 1]));
                    int res = table[get_int(a[k-1])][get_int(a[k])][i][j];
                    if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
                        r = -1;
                        break;
                    }
                    r += (res-1);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
//                cout << r << " ";
            }
        }
//        cout << endl;
    }

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            cout << rr[i][j] << " ";
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            for(int x = 0; x < 10; x++) {
//                for(int y = 0; y < 10; y++) {
//                    int r1 = shortest(x, y, i, j);
//                    int r2 = bfs(x, y, i, j);
//
//                    cout << r1 << " " << r2;
//                    if(r1 != r2) cout << "GRESKA";
//
//                    cout << endl;
//                }
//            }
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    // string s(1, c);
    // return stoi(s);
    return (int)(c - 48);
}

int bfs(int i, int j, int src, int tar) {
//    cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    bool visited[10] = {0};
    q.push({src, 0});

    while (!q.empty()) {
        Node curr = q.front();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

//        if (curr.val % 10 == tar) {
//            return curr.dist - 1;
//        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

        if(i_d == tar || j_d == tar) {
            return curr.dist;
        }
//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visited[i_d]) {
            q.push({i_d, curr.dist + 1});
            visited[i_d] = true;
        }
        if(!visited[j_d]) {
            q.push({j_d, curr.dist + 1});
            visited[j_d] = true;
        }

        q.pop();
    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    int table[10][10][10][10];

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    table[i][j][x][y] = -2;
                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res;
                    if(table[get_int(a[k])][get_int(a[k+1])][i][j] != -2) {
                        res = table[get_int(a[k])][get_int(a[k+1])][i][j];
                    }
                    else {
                        res = bfs(i, j, get_int(a[k]), get_int(a[k+1]));
                        table[get_int(a[k])][get_int(a[k+1])][i][j] = res;
                    }

                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += (res);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    q.push({src, 0});
    int s = 0;
    int visitedDigits[10] = {0};
    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val % 10 == tar) {
            return curr.dist - 1;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res = bfs(i, j, get_int(a[k]), get_int(a[k + 1]));
                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += res;
                }
                rr[i][j] = r;
                rr[j][i] = r;
                if (i == 0) {
                    rr[j][j] = r;
                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val == tar) {
            if(curr.dist == 0) return curr.dist;
            return curr.dist - 1;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res = bfs(i, j, get_int(a[k]), get_int(a[k + 1]));
                    if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
                        r = -1;
                        break;
                    }
                    r += res;
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            int r = bfs()
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val % 10 == tar) {
            if(curr.dist == 0) return curr.dist;
            return curr.dist - 1;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res = bfs(i, j, get_int(a[k]), get_int(a[k + 1]));
                    if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
                        r = -1;
                        break;
                    }
                    r += res;
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            int r = bfs()
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val % 10 == tar) {
            return curr.dist - 1;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res = bfs(i, j, get_int(a[k]), get_int(a[k + 1]));
                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += res;
                }
                rr[i][j] = r;
                rr[j][i] = r;
                if (i == 0) {
                    rr[j][j] = r;
                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

//int bfs(int i, int j, int s, int e) {
//    queue<int> q;
//    unordered_map<int, int> dist;
//
//    q.push(s);
//    dist[s] = 0;
//
//    int result = 0;
//    while(!q.empty()) {
//        int n = q.front();
//        q.pop();
//        int d = dist[n];
//
//        int next = (n + i) % 10;
//        if(next == e)
//            return d;
//        if(dist.find(next) == dist.end()) {
//            q.push(next);
//            dist[next] =  d + 1;
//        }
//
//        next = (n + j) % 10;
//        if(next == e)
//            return d;
//        if(dist.find(next) == dist.end()) {
//            q.push(next);
//            dist[next] =  d + 1;
//        }
//    }
//
//    return -1;
//}

int bfs(int i, int j, int src, int tar) {
//    cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    bool visited[10] = {0};
    q.push({src, 0});

    while (!q.empty()) {
        Node curr = q.front();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

//        if (curr.val % 10 == tar) {
//            return curr.dist - 1;
//        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

        if(i_d == tar || j_d == tar) {
            return curr.dist;
        }
//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visited[i_d]) {
            q.push({i_d, curr.dist + 1});
            visited[i_d] = true;
        }
        if(!visited[j_d]) {
            q.push({j_d, curr.dist + 1});
            visited[j_d] = true;
        }

        q.pop();
    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    int table[10][10][10][10];

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    table[i][j][x][y] = -2;
                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res;

                    if(table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] != -2) {
                        res = table[(int)a[k] - 48][(int)a[k+1] - 48][i][j];
                    }
                    else {
                        res = bfs(i, j, (int)a[k] - 48, (int)a[k+1] - 48);
                        table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] = res;
                    }

                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += res;
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

//    cout << bfs(3, 2, 4, 8) << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    int table[10][10][10][10];

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    table[i][j][x][y] = -2;
                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res;
                    if(table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] != -2)
                        res = table[(int)a[k] - 48][(int)a[k+1] - 48][i][j];
                    else
                        res = bfs(i, j, (int)a[k] - 48, (int)a[k+1] - 48);

                    table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] = res;

                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += (res-1);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int shortest(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val == tar) {
            return curr.dist;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int table[10][10][10][10];
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    int r = shortest(x, y, i, j);
                    table[i][j][x][y] = r;
                    table[i][j][y][x] = r;
                }
            }
        }
    }

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {

//                    int res = shortest(i, j, get_int(a[k]), get_int(a[k + 1]));
                    int res = table[get_int(a[k])][get_int(a[k + 1])][i][j];
                    if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
                        r = -1;
                        break;
                    }
                    r += (res-1);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            for(int x = 0; x < 10; x++) {
//                for(int y = 0; y < 10; y++) {
//                    int r1 = shortest(x, y, i, j);
//                    int r2 = bfs(x, y, i, j);
//
//                    cout << r1 << " " << r2;
//                    if(r1 != r2) cout << "GRESKA";
//
//                    cout << endl;
//                }
//            }
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int shortest(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val == tar) {
            return curr.dist;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int table[10][10][10][10];
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    int r = shortest(x, y, i, j);
                    table[i][j][x][y] = r;
                    table[i][j][y][x] = r;
                }
            }
        }
    }

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = i; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 1; k < a.size(); k++) {

//                    int res = shortest(i, j, get_int(a[k]), get_int(a[k + 1]));
                    int res = table[get_int(a[k-1])][get_int(a[k])][i][j];
                    if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
                        r = -1;
                        break;
                    }
                    r += (res-1);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            for(int x = 0; x < 10; x++) {
//                for(int y = 0; y < 10; y++) {
//                    int r1 = shortest(x, y, i, j);
//                    int r2 = bfs(x, y, i, j);
//
//                    cout << r1 << " " << r2;
//                    if(r1 != r2) cout << "GRESKA";
//
//                    cout << endl;
//                }
//            }
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    int table[10][10][10][10];

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    table[i][j][x][y] = -2;
                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res;
                    if(table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] != -2)
                        res = table[(int)a[k] - 48][(int)a[k+1] - 48][i][j];
                    else
                        res = bfs(i, j, (int)a[k] - 48, (int)a[k+1] - 48);

                    table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] = res;

                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += (res-1);
                }
                rr[i][j] = r;
                rr[j][i] = r;
                if (i == 0) {
                    rr[j][j] = r;
                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int shortest(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val == tar) {
            return curr.dist - 1;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res = shortest(i, j, get_int(a[k]), get_int(a[k + 1]));
                    if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
                        r = -1;
                        break;
                    }
                    r += (res-1);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            for(int x = 0; x < 10; x++) {
//                for(int y = 0; y < 10; y++) {
//                    int r1 = shortest(x, y, i, j);
//                    int r2 = bfs(x, y, i, j);
//
//                    cout << r1 << " " << r2;
//                    if(r1 != r2) cout << "GRESKA";
//
//                    cout << endl;
//                }
//            }
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val == tar) {
            if(curr.val == 0) return curr.dist;
            return curr.dist - 1;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res = bfs(i, j, get_int(a[k]), get_int(a[k + 1]));
                    if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
                        r = -1;
                        break;
                    }
                    r += res;
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            int r = bfs()
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val % 10 == tar) {
            return curr.dist - 1;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res = bfs(i, j, get_int(a[k]), get_int(a[k + 1]));
                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += res;
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int shortest(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int bfs(int i, int j, int src, int tar) {
    //cout << i << " " << j << " ULAZ " << src << " " << tar << endl;
    queue<Node> q;
    int visitedDigits[10] = {0};

    q.push({src, 0});
//    visitedDigits[src] = 1;

    while (!q.empty()) {
        Node curr = q.front();
        q.pop();
        //cout << curr.val << "  NODE " << curr.dist << endl;
//        if (curr.dist > 50) {
//            return -1;
//        }

        if (curr.val == tar) {
            return curr.dist - 1;
        }

        int i_d = (i + curr.val) % 10;
        int j_d = (j + curr.val) % 10;

//        if (i_d - curr.val != 0) {
//            q.push({i_d, curr.dist + 1});
//        }
//
//        if (j_d - curr.val != 0) {
//            q.push({j_d, curr.dist + 1});
//        }

        if(!visitedDigits[i_d]) {
            q.push({i_d, curr.dist + 1});
            visitedDigits[i_d] = 1;
        }
        if(!visitedDigits[j_d]) {
            q.push({j_d, curr.dist + 1});
            visitedDigits[j_d] = 1;
        }

    }

    return -1;
}

int table[10][10][10][10];

int minimumMissing(int i, int j, string &a) {
    int r = 0;
    for (int k = 1; k < a.size(); k++) {

//                    int res = shortest(i, j, get_int(a[k]), get_int(a[k + 1]));
        int res = table[(int)a[k-1] - 48][(int)a[k] - 48][i][j];
        if (res == -1) {
//                        cout << "greska: " << get_int(a[k]) << " " << get_int(a[k + 1]) << endl;
            r = -1;
            break;
        }
        r += (res);
    }
    return r;
}

int main() {

    string a;
    cin >> a;

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    int r = shortest(x, y, i, j);
                    table[i][j][x][y] = r;
                    table[i][j][y][x] = r;
                }
            }
        }
    }

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = i; j < 10; j++) {
            int r = minimumMissing(i, j, a);
            rr[i][j] = r;
            rr[j][i] = r;
        }
    }

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            cout << rr[i][j] << " ";
        }
        cout << endl;
    }

//    for(int i = 0; i < 10; i++) {
//        for(int j = 0; j < 10; j++) {
//            for(int x = 0; x < 10; x++) {
//                for(int y = 0; y < 10; y++) {
//                    int r1 = shortest(x, y, i, j);
//                    int r2 = bfs(x, y, i, j);
//
//                    cout << r1 << " " << r2;
//                    if(r1 != r2) cout << "GRESKA";
//
//                    cout << endl;
//                }
//            }
//        }
//    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int val, dist;
};

int get_int(char c) {
    string s(1, c);
    return stoi(s);
}

int bfs(int i, int j, int s, int e) {
    queue<int> q;
    unordered_map<int, int> dist;

    q.push(s);
    dist[s] = 0;

    int result = 0;
    while(!q.empty()) {
        int n = q.front();
        q.pop();
        int d = dist[n];

        int next = (n + i) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }

        next = (n + j) % 10;
        if(next == e)
            return d + 1;
        if(dist.find(next) == dist.end()) {
            q.push(next);
            dist[next] =  d + 1;
        }
    }

    return -1;
}

int main() {

    string a;
    cin >> a;

    int rr[10][10];

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            rr[i][j] = -2;
        }
    }

    int table[10][10][10][10];

    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            for(int x = 0; x < 10; x++) {
                for(int y = x; y < 10; y++) {
                    table[i][j][x][y] = -2;
                }
            }
        }
    }

    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (rr[i][j] != -2) {
                cout << rr[i][j] << " ";
            } else {
                int r = 0;
                for (int k = 0; k < a.size() - 1; k++) {
                    int res;
                    table[(int)a[k] - 48][(int)a[k+1] - 48][i][j]
                    if(table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] != -2) {
                        res = table[(int)a[k] - 48][(int)a[k+1] - 48][i][j];
                    }
                    else {
                        res = bfs(i, j, get_int(a[k]), get_int(a[k+1]));
                        table[(int)a[k] - 48][(int)a[k+1] - 48][i][j] = res;
                    }

                    if (res == -1) {
                        r = -1;
                        break;
                    }
                    r += (res-1);
                }
                rr[i][j] = r;
                rr[j][i] = r;
//                if (i == 0) {
//                    rr[j][j] = r;
//                }
                cout << r << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define LL long long int
#define NOS ios_base::sync_with_stdio(false);cin.tie(NULL);

int ans[10][10][10];
int anss[10][10][10][10];

int output[10][10];

int main()
{
    NOS
    memset(ans, -1, sizeof ans);
    memset(anss, -1, sizeof anss);
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            int cs = 1;
            int k = j;
            k += i;
            int nn = k % 10;
            while(ans[i][j][nn] == -1)
            {
                ans[i][j][nn] = cs;
                cs++;
                k += i;
                nn = k % 10;
            }
        }
    }
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            for(int k = 0; k < 10; k++)
            {
                if(i == j)
                {
                    for(int p = 0; p < 10; p++)
                        anss[i][j][k][p] = anss[j][i][k][p] = ans[i][k][p];

                }
                else
                {

                    for(int p = 0; p < 10; p++)
                    {
                        int mins = 99999;
                        for(int q = 0; q < 10; q++)
                        {
                            if(ans[i][k][q] != -1 && ans[j][q][p] != -1)
                            {
                                int xx = 0;
                                if(p == q)
                                    xx = ans[i][k][q];
                                else if(q == k)
                                    xx = ans[j][q][p];
                                else
                                    xx = ans[i][k][q] + ans[j][q][p];
                                if(mins > xx)
                                    mins = xx;
                            }
                        }
                        if(mins != 99999)
                            anss[i][j][k][p] = anss[j][i][k][p] = mins;
                    }
                }
            }
        }
    }
    string s;
    cin >> s;
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            LL cnt = 0;
            int st = 0;
            int flag = 0;
            for(int ns = 1; ns < s.length(); ns++)
            {
                if(anss[i][j][st][s[ns] - '0'] == -1)
                {
                    output[i][j] = output[j][i] = -1;
                    flag = 1;
                    break;
                }
                else
                {
                    cnt += (anss[i][j][st][s[ns] - '0'] - 1);
                    st = s[ns] - '0';
                }
            }
            if(flag == 0)
                output[i][j] = output[j][i] = cnt;
        }
    }
    for(int i = 0; i < 10; i++)
    {
        cout << output[i][0];
        for(int j = 1; j < 10; j++)
        {
            cout << " " << output[i][j] ;
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define LL long long int
#define NOS ios_base::sync_with_stdio(false);cin.tie(NULL);

int ans[10][10][10];
int anss[10][10][10][10];

LL output[10][10];

int main()
{
    NOS
    memset(ans, -1, sizeof ans);
    memset(anss, -1, sizeof anss);
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            int cs = 1;
            int k = j;
            k += i;
            int nn = k % 10;
            while(ans[i][j][nn] == -1)
            {
                ans[i][j][nn] = cs;
                cs++;
                k += i;
                nn = k % 10;
            }
        }
    }
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            for(int k = 0; k < 10; k++)
            {
                if(i == j)
                {
                    for(int p = 0; p < 10; p++)
                        anss[i][j][k][p] = anss[j][i][k][p] = ans[i][k][p];

                }
                else
                {

                    for(int p = 0; p < 10; p++)
                    {
                        int mins = 99999;
                        for(int q = 0; q < 10; q++)
                        {
                            if(ans[i][k][q] != -1 && ans[j][q][p] != -1)
                            {
                                int xx = 0;
                                if(p == q && q == k)
                                    xx = min(ans[i][k][q], ans[j][q][p]);
                                else if(p == q)
                                    xx = ans[i][k][q];
                                else if(q == k)
                                    xx = ans[j][q][p];
                                else
                                    xx = ans[i][k][q] + ans[j][q][p];
                                if(mins > xx)
                                    mins = xx;
                            }
                        }
                        if(mins != 99999)
                            anss[i][j][k][p] = anss[j][i][k][p] = mins;
                    }
                }
            }
        }
    }
    cout << anss[0][1][5][5] << endl;
    string s;
    cin >> s;
    if(s.length() == 1)
    {
        for(int i = 0; i < 10; i++)
        {
            cout << 1;
            for(int j = 1; j < 10; j++)
            {
                cout << " " << 1 ;
            }
            cout << endl;
        }
        return 0;
    }
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            LL cnt = 0;
            int st = 0;
            int flag = 0;
            for(int ns = 1; ns < s.length(); ns++)
            {
                if(anss[i][j][st][s[ns] - '0'] == -1)
                {
                    output[i][j] = output[j][i] = -1;
                    flag = 1;
                    break;
                }
                else
                {
                    cnt += (anss[i][j][st][s[ns] - '0'] - 1);
                    st = s[ns] - '0';
                }
            }
            if(flag == 0)
                output[i][j] = output[j][i] = cnt;
        }
    }
    for(int i = 0; i < 10; i++)
    {
        cout << output[i][0];
        for(int j = 1; j < 10; j++)
        {
            cout << " " << output[i][j] ;
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define LL long long int
#define NOS ios_base::sync_with_stdio(false);cin.tie(NULL);

int ans[10][10][10];
int anss[10][10][10][10];

LL output[10][10];

int main()
{
    NOS
    memset(ans, -1, sizeof ans);
    memset(anss, -1, sizeof anss);
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            int cs = 1;
            int k = j;
            k += i;
            int nn = k % 10;
            while(ans[i][j][nn] == -1)
            {
                ans[i][j][nn] = cs;
                cs++;
                k += i;
                nn = k % 10;
            }
        }
    }
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            for(int k = 0; k < 10; k++)
            {
                if(i == j)
                {
                    for(int p = 0; p < 10; p++)
                        anss[i][j][k][p] = anss[j][i][k][p] = ans[i][k][p];

                }
                else
                {

                    for(int p = 0; p < 10; p++)
                    {
                        int mins = 99999;
                        for(int q = 0; q < 10; q++)
                        {
                            if(ans[i][k][q] != -1 && ans[j][q][p] != -1)
                            {
                                int xx = 0;
                                if(p == q)
                                    xx = ans[i][k][q];
                                else if(q == k)
                                    xx = ans[j][q][p];
                                else
                                    xx = ans[i][k][q] + ans[j][q][p];
                                if(mins > xx)
                                    mins = xx;
                            }
                        }
                        if(mins != 99999)
                            anss[i][j][k][p] = anss[j][i][k][p] = mins;
                    }
                }
            }
        }
    }
    string s;
    cin >> s;
    if(s.length() == 1)
    {
        for(int i = 0; i < 10; i++)
        {
            cout << 1;
            for(int j = 1; j < 10; j++)
            {
                cout << " " << 1 ;
            }
            cout << endl;
        }
        return 0;
    }
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            LL cnt = 0;
            int st = 0;
            int flag = 0;
            for(int ns = 1; ns < s.length(); ns++)
            {
                if(anss[i][j][st][s[ns] - '0'] == -1)
                {
                    output[i][j] = output[j][i] = -1;
                    flag = 1;
                    break;
                }
                else
                {
                    cnt += (anss[i][j][st][s[ns] - '0'] - 1);
                    st = s[ns] - '0';
                }
            }
            if(flag == 0)
                output[i][j] = output[j][i] = cnt;
        }
    }
    for(int i = 0; i < 10; i++)
    {
        cout << output[i][0];
        for(int j = 1; j < 10; j++)
        {
            cout << " " << output[i][j] ;
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define LL long long int
#define NOS ios_base::sync_with_stdio(false);cin.tie(NULL);

int ans[10][10][10];
int anss[10][10][10][10];

LL output[10][10];

int main()
{
    NOS
    memset(ans, -1, sizeof ans);
    memset(anss, -1, sizeof anss);
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            int cs = 1;
            int k = j;
            k += i;
            int nn = k % 10;
            while(ans[i][j][nn] == -1)
            {
                ans[i][j][nn] = cs;
                cs++;
                k += i;
                nn = k % 10;
            }
        }
    }
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            for(int k = 0; k < 10; k++)
            {
                if(i == j)
                {
                    for(int p = 0; p < 10; p++)
                        anss[i][j][k][p] = anss[j][i][k][p] = ans[i][k][p];

                }
                else
                {

                    for(int p = 0; p < 10; p++)
                    {
                        int mins = 99999;
                        for(int q = 0; q < 10; q++)
                        {
                            if(ans[i][k][q] != -1 && ans[j][q][p] != -1)
                            {
                                int xx = 0;
                                if(p == q)
                                    xx = ans[i][k][q];
                                else if(q == k)
                                    xx = ans[j][q][p];
                                else
                                    xx = ans[i][k][q] + ans[j][q][p];
                                if(mins > xx)
                                    mins = xx;
                            }
                        }
                        if(mins != 99999)
                            anss[i][j][k][p] = anss[j][i][k][p] = mins;
                    }
                }
            }
        }
    }
    string s;
    cin >> s;
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            LL cnt = 0;
            int st = 0;
            int flag = 0;
            for(int ns = 1; ns < s.length(); ns++)
            {
                if(anss[i][j][st][s[ns] - '0'] == -1)
                {
                    output[i][j] = output[j][i] = -1;
                    flag = 1;
                    break;
                }
                else
                {
                    cnt += (anss[i][j][st][s[ns] - '0'] - 1);
                    st = s[ns] - '0';
                }
            }
            if(flag == 0)
                output[i][j] = output[j][i] = cnt;
        }
    }
    for(int i = 0; i < 10; i++)
    {
        cout << output[i][0];
        for(int j = 1; j < 10; j++)
        {
            cout << " " << output[i][j] ;
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define LL long long int
#define NOS ios_base::sync_with_stdio(false);cin.tie(NULL);

int ans[10][10][10];
int anss[10][10][10][10];

LL output[10][10];

int main()
{
    NOS
    memset(ans, -1, sizeof ans);
    memset(anss, -1, sizeof anss);
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            int cs = 1;
            int k = j;
            k += i;
            int nn = k % 10;
            while(ans[i][j][nn] == -1)
            {
                ans[i][j][nn] = cs;
                cs++;
                k += i;
                nn = k % 10;
            }
        }
    }
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            for(int k = 0; k < 10; k++)
            {
                if(i == j)
                {
                    for(int p = 0; p < 10; p++)
                        anss[i][j][k][p] = anss[j][i][k][p] = ans[i][k][p];

                }
                else
                {

                    for(int p = 0; p < 10; p++)
                    {
                        int mins = 99999;
                        for(int q = 0; q < 10; q++)
                        {
                            if(ans[i][k][q] != -1 && ans[j][q][p] != -1)
                            {
                                int xx = 0;
                                if(p == q && q == k)
                                    xx = min(ans[i][k][q], ans[j][q][p]);
                                else if(p == q)
                                    xx = ans[i][k][q];
                                else if(q == k)
                                    xx = ans[j][q][p];
                                else
                                    xx = ans[i][k][q] + ans[j][q][p];
                                if(mins > xx)
                                    mins = xx;
                            }
                        }
                        if(mins != 99999)
                            anss[i][j][k][p] = anss[j][i][k][p] = mins;
                    }
                }
            }
        }
    }
    string s;
    cin >> s;
    if(s.length() == 1)
    {
        for(int i = 0; i < 10; i++)
        {
            cout << 0;
            for(int j = 1; j < 10; j++)
            {
                cout << " " << 0 ;
            }
            cout << endl;
        }
        return 0;
    }
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            LL cnt = 0;
            int st = 0;
            int flag = 0;
            for(int ns = 1; ns < s.length(); ns++)
            {
                if(anss[i][j][st][s[ns] - '0'] == -1)
                {
                    output[i][j] = output[j][i] = -1;
                    flag = 1;
                    break;
                }
                else
                {
                    cnt += (anss[i][j][st][s[ns] - '0'] - 1);
                    st = s[ns] - '0';
                }
            }
            if(flag == 0)
                output[i][j] = output[j][i] = cnt;
        }
    }
    for(int i = 0; i < 10; i++)
    {
        cout << output[i][0];
        for(int j = 1; j < 10; j++)
        {
            cout << " " << output[i][j] ;
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define LL long long int
#define NOS ios_base::sync_with_stdio(false);cin.tie(NULL);

int ans[10][10][10];
int anss[10][10][10][10];

LL output[10][10];

int main()
{
    NOS
    memset(ans, -1, sizeof ans);
    memset(anss, -1, sizeof anss);
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < 10; j++)
        {
            int cs = 1;
            int k = j;
            k += i;
            int nn = k % 10;
            while(ans[i][j][nn] == -1)
            {
                ans[i][j][nn] = cs;
                cs++;
                k += i;
                nn = k % 10;
            }
        }
    }
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            for(int k = 0; k < 10; k++)
            {
                if(i == j)
                {
                    for(int p = 0; p < 10; p++)
                        anss[i][j][k][p] = anss[j][i][k][p] = ans[i][k][p];

                }
                else
                {

                    for(int p = 0; p < 10; p++)
                    {
                        int mins = 99999;
                        for(int q = 0; q < 10; q++)
                        {
                            if(ans[i][k][q] != -1 && ans[j][q][p] != -1)
                            {
                                int xx = 0;
                                if(p == q && q == k)
                                    xx = min(ans[i][k][q], ans[j][q][p]);
                                else if(p == q)
                                    xx = ans[i][k][q];
                                else if(q == k)
                                    xx = ans[j][q][p];
                                else
                                    xx = ans[i][k][q] + ans[j][q][p];
                                if(mins > xx)
                                    mins = xx;
                            }
                        }
                        if(mins != 99999)
                            anss[i][j][k][p] = anss[j][i][k][p] = mins;
                    }
                }
            }
        }
    }
    string s;
    cin >> s;
    if(s.length() == 1)
    {
        for(int i = 0; i < 10; i++)
        {
            cout << 1;
            for(int j = 1; j < 10; j++)
            {
                cout << " " << 1 ;
            }
            cout << endl;
        }
        return 0;
    }
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j <= i; j++)
        {
            LL cnt = 0;
            int st = 0;
            int flag = 0;
            for(int ns = 1; ns < s.length(); ns++)
            {
                if(anss[i][j][st][s[ns] - '0'] == -1)
                {
                    output[i][j] = output[j][i] = -1;
                    flag = 1;
                    break;
                }
                else
                {
                    cnt += (anss[i][j][st][s[ns] - '0'] - 1);
                    st = s[ns] - '0';
                }
            }
            if(flag == 0)
                output[i][j] = output[j][i] = cnt;
        }
    }
    for(int i = 0; i < 10; i++)
    {
        cout << output[i][0];
        for(int j = 1; j < 10; j++)
        {
            cout << " " << output[i][j] ;
        }
        cout << endl;
    }
}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <set>
#include <numeric>
#include <queue>
#include <map>

using namespace std;

int dfs(int cur, int goal ,int x,int y){
    queue<tuple<int,int>> que;
    que.push(make_tuple(cur,0));
    int visited[10] = {};
    while(!que.empty()){
        tuple<int,int> elem = que.front();
        que.pop();
        if(get<0>(elem) == goal && get<1>(elem)!=0){
            return get<1>(elem);
        }
        //cout << get<0>(elem);
        if(!visited[get<0>(elem)]){
            //cout << "test2" << endl;
            que.push(make_tuple((get<0>(elem)+x) %10,get<1>(elem)+1));
            que.push(make_tuple((get<0>(elem)+y)%10,get<1>(elem)+1));
            //cout << "test" << endl;
        }
        visited[get<0>(elem)] = true;
        //cout << "test" << endl;
    }

    return 100;

}

int main(){
    string line;
    cin >> line;
    int n = line.size();
    for(int x=0;x<10;x++){
        for(int y = 0;y<10;y++){
            long long int result = 0;
            int last = 0;
            bool possible = true;
            int dp[10][10];
            for(int i = 0;i<10;i++){
                for(int j = 0;j<10;j++){

                    dp[i][j] = dfs(i,j,x,y);
                }
            }
            for(int i = 0;i<n;i++){
                int total = dp[last][line[i]-'0'];
                if(total == 100){
                    possible = false;
                }else{
                    result += total-1;
                }
                last = line[i]-'0';
            }

            if(possible){
                cout << result << " ";
            }else{
                cout << -1 << " ";
            }
        }
        cout << endl;
    }

}


#include <iostream>
#include <math.h>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <set>
#include <numeric>
#include <queue>
#include <map>

using namespace std;

int dfs(int cur, int goal ,int x,int y){
    queue<tuple<int,int>> que;
    que.push(make_tuple(cur,0));
    int visited[10] = {};
    while(!que.empty()){
        tuple<int,int> elem = que.front();
        que.pop();
        if(get<0>(elem) == goal && get<1>(elem)!=0){
            return get<1>(elem);
        }
        //cout << get<0>(elem);
        if(!visited[get<0>(elem)]){
            //cout << "test2" << endl;
            que.push(make_tuple((get<0>(elem)+x) %10,get<1>(elem)+1));
            que.push(make_tuple((get<0>(elem)+y)%10,get<1>(elem)+1));
            //cout << "test" << endl;
        }
        visited[get<0>(elem)] = true;

        //cout << "test" << endl;
    }

    return 100;

}

int main(){
    string line;
    cin >> line;
    int n = line.size();
    for(int x=1;x<=1;x++){
        for(int y = 1;y<=1;y++){
            long long int result = 0;
            int last = line[0]-'0';
            bool possible = true;
            int dp[10][10];
            for(int i = 0;i<10;i++){
                for(int j = 0;j<10;j++){

                    dp[i][j] = dfs(i,j,x,y);
                }
            }
            for(int i = 1;i<n;i++){
                int total = dp[last][line[i]-'0'];
                //cout << total << endl;
                if(total == 100){
                    possible = false;
                }else{
                    result += total-1;
                }
                last = line[i]-'0';
            }

            if(possible){
                cout << result << " ";
            }else{
                cout << -1 << " ";
            }
        }
        cout << endl;
    }

}