1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream>
#include <map>

using namespace std;
using ull = unsigned long long;

ull reduce(ull n)
{
    ull r = n;
    while (r > 9) {
        ull w = 1;
        while (r > 0) {
            w *= r % 10;
            r /= 10;
        }
        r = w;
    }
    return r;
}

map<ull, ull> solve_99(int l, bool zero = true)
{
    map<ull, ull> res;
    if (l == 0) {
        res.insert({ 1, 1 });
        return res;
    }
    map<ull, ull> tab;
    for (int i = !zero; i < 10; i++) {
        tab.insert({ i, 1 });
        if (!zero || l == 1) {
            res.insert({ i, 1 });
        }
    }
    for (int i = 1; i < l; i++) {
        map<ull, ull> newtab;
        for (auto [k, v] : tab) {
            for (int j = 0; j < 10; j++) {
                ull a = k * j;
                if (a % 10 == 0) {
                    a = 0;
                }
                if (newtab.find(a) != newtab.end()) {
                    newtab[a] += v;
                } else {
                    newtab.insert({ a, v });
                }
            }
        }
        for (auto [k, v] : newtab) {
            if (res.find(k) != res.end()) {
                res[k] += v;
            } else {
                res.insert({ k, v });
            }
        }
        tab = std::move(newtab);
    }

    return res;
}

map<ull, ull> mulmap(const map<ull, ull>& m, int c)
{
    map<ull, ull> res;
    for (auto [k, v] : m) {
        ull a = k * c;
        if (a % 10 == 0) {
            a = 0;
        }
        if (res.find(a) != res.end()) {
            res[a] += v;
        } else {
            res.insert({ a, v });
        }
    }
    return res;
}

void addmap(map<ull, ull>& m1, const map<ull, ull>& m2)
{
    for (auto [k, v] : m2) {
        if (m1.find(k) != m1.end()) {
            m1[k] += v;
        } else {
            m1.insert({ k, v });
        }
    }
}

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    for (int q = 0; q < t; q++) {
        map<ull, ull> res;
        for (int i = 0; i < 10; i++) {
            res.insert({ i, 0 });
        }

        ull n;
        cin >> n;
        int l = 0;
        ull m = n;
        ull p = 1;

        while (m > 0) {
            p *= m % 10;
            m /= 10;
        }

        if (p == 0) {
            res[0] += 1;
        }

        while (n > 0) {
            ull m = n / 10;
            ull p = 1;
            while (m > 0) {
                p *= m % 10;
                m /= 10;
            }

            ull u = n % 10;
            auto r = solve_99(l);
            if (n != u) {
                if (u != 0) {
                    addmap(res, mulmap(r, 0));
                }
            } else if (l != 0) {
                addmap(res, solve_99(l, false));
            }
            for (int i = 1; i < u + (l == 0); i++) {
                addmap(res, mulmap(r, i * p));
            }
            n /= 10;
            l += 1;
        }

        for (auto [k, v] : res) {
            if (k > 9) {
                res[reduce(k)] += v;
            }
        }
        for (int i = 0; i < 9; i++) {
            cout << res[i] << " ";
        }
        cout << res[9] << endl;
    }

    return 0;
}