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
156
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define RFOR(i,p,n) for(int i=(p);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ssize(x) int((x).size())
#define fi first
#define se second
#define V vector
#define pb push_back
#define eb emplace_back
#define C const
#define pn printf("\n")
using namespace std;
typedef long long ll;
typedef V<int> vi;
typedef V<ll> vll;
typedef const int ci;
typedef const ll cll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void chmin(auto &a, auto b){a=min(a,b);}
void chmax(auto &a, auto b){a=max(a,b);}
ci inf = 2.1e9;
cll infll = 4.5e18;

int I(){
    int z;
    scanf("%d", &z);
    //cin >> z;
    return z;
}

// iloczyn i cyfr bez ograniczeń
V<pll> tab[20];

// wynik dla liczb mniejszych niż pot 10
// czyli dla liczb co mają co najwyżej tyle cyfr
V<pll> tab2[20];

V<pll> tab_cyf[20][10];
V<pll> tab_cyf_bez_zera[20][10];

vll wynik_pot10[20];

const int cap = 1000000;
int iloczyn[cap];
int iloczyn_z_zerami[cap];

int wylicz_tab[cap];

V<pll> kompresuj(V<pll> vec){
    sort(all(vec));
    V<pll> ret;
    for(pll t : vec){
        if(ssize(ret) && ret.back().fi == t.fi) ret.back().se += t.se;
        else ret.eb(t);
    }
    return ret;
}

ll wylicz(ll x){
    while(x >= cap){
        ll ilo = 1;
        while(x >= cap) ilo *= iloczyn_z_zerami[x%cap], x /= cap;
        x = ilo*iloczyn[x];
    }
    return wylicz_tab[x];
}

void prep(){
    int dl = 19;
    tab[0].eb(1ll, 1ll);
    REP(i, dl){
        for(auto [ilo, ile] : tab[i]) REP(cyf, 10) tab[i+1].eb(ilo*cyf, ile);
        tab[i+1] = kompresuj(tab[i+1]);
    }

    FOR(i, 1, dl){
        FOR(j, 1, i) FOR(cyf, 1, 9) for(auto [ilo, ile] : tab[j-1]) tab2[i].eb(ilo*cyf, ile);
        tab2[i] = kompresuj(tab2[i]);
    }

    REP(i, cap){
        int ilo = 1;
        for(int tmp = i; tmp; tmp /= 10) ilo *= tmp%10;
        iloczyn[i] = ilo;
        iloczyn_z_zerami[i] = i<cap/10 ? 0 : ilo;
    }

    REP(i, cap){
        if(i < 10) wylicz_tab[i] = i;
        else{
            assert(iloczyn[i] < i);
            wylicz_tab[i] = wylicz_tab[iloczyn[i]];
        }
    }

    FOR(i, 0, dl){
        vll wyn(10, 0);
        for(auto [ilo, ile] : tab2[i]) wyn[wylicz(ilo)] += ile;
        wynik_pot10[i] = wyn;
    }

    FOR(i, 1, dl){
        FOR(j, 1, 9){
            tab_cyf[i][j] = tab_cyf[i][j-1];
            tab_cyf_bez_zera[i][j] = tab_cyf_bez_zera[i][j-1];
            for(auto [ilo, ile] : tab[i-1]) tab_cyf[i][j].eb(ilo*(j-1), ile);
            if(j-1) for(auto [ilo, ile] : tab[i-1]) tab_cyf_bez_zera[i][j].eb(ilo*(j-1), ile);
            tab_cyf[i][j] = kompresuj(tab_cyf[i][j]);
            tab_cyf_bez_zera[i][j] = kompresuj(tab_cyf_bez_zera[i][j]);
        }
    }
}

void answer(){
    ll n;
    scanf("%lld", &n);
    ++n;
    vi cyfry;
    for(ll tmp = n; tmp; tmp /= 10) cyfry.eb(tmp%10);
    reverse(all(cyfry));
    int dl = ssize(cyfry);

    vll wyn = wynik_pot10[dl-1];
    ll pref = 1;
    REP(poz, dl){
        if(!poz){
            for(auto [ilo, ile] : tab_cyf_bez_zera[dl-poz][cyfry[poz]]){
                wyn[wylicz(pref * ilo)] += ile;
            }
        }
        else{
            for(auto [ilo, ile] : tab_cyf[dl-poz][cyfry[poz]]){
                wyn[wylicz(pref * ilo)] += ile;
            }
        }
        pref *= cyfry[poz];
    }
    for(ll x : wyn) printf("%lld ", x);
    pn;
}

int main(){
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    prep();
    int tt = 1;
    tt = I();
    while(tt--) answer();
}