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
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

vector<pair<LL,LL>> tab;
vector<LL> sil;

LL fun(LL n){
    if(n<=9)return n;
    LL a=1;
    while(n>0){
        a*=n%10;
        n/=10;
    }
    return fun(a);
}
void fun(LL akt, LL ost){
    if(akt>=1e18)return;
    LL tmp = fun(akt);
    if(tmp!=0){
        tab.push_back({akt, tmp});
    }
    for(LL i=ost;i<=9;i++){
        if(akt<=1e17)fun(akt*10+i, i);
    }
}

LL newton(LL n, LL k){
    if(k>n)return 0;
    return sil[n]/(sil[k]*sil[n-k]);
}

LL permutations(vector<int> &cnt,int sum){
    // int sum = 0;
    // for(int i=1;i<10;i++)sum+=cnt[i];
    // if(sum==0 && ones==0)return 0;
    LL res = sil[sum];
    for(int i=1;i<10;i++){
        res/=sil[cnt[i]];
    }
    // res *= newton(sum+ones,ones);
    return res;
}
LL calc(vector<int> &a,LL perm, int sum, string &N, int ind, bool flag=0){
    if(ind>=N.size())return (int)(sum==0);
    if(N.size()-ind<sum)return 0;
    LL wyn=0;
    // perm = permutations(a,sum);
    if(flag){
        int m = N.size()-ind-sum-1;
        // wyn+=permutations(a,sum)*newton(sum+m+1,m);
        wyn+=perm*newton(sum+m+1,m);
        // for(int i=0;i<N.size()-ind-sum;i++)wyn+=permutations(a,sum, i);
    }
    // for(int i=0;i<N.size()-ind-sum;i++)wyn+=permutations(a, i);
    // cout<<wyn<<endl;
    for(int i=1;i<N[ind]-'0';i++){
        if(i==1){
            // wyn+=permutations(a,sum, N.size()-ind-sum-1);
            wyn+=perm*newton(N.size()-ind-1,N.size()-ind-sum-1);
        }else{
            if(a[i]==0)continue;
            // a[i]--;
            // wyn+=permutations(a,sum-1, N.size()-ind-sum);
            wyn+=(perm*((LL)a[i])*newton(N.size()-ind-1,N.size()-ind-sum))/sum;
            // a[i]++;
        }
    }
    if(a[N[ind]-'0']!=0 || N[ind]-'0'==1){
        if(N[ind]-'0'==1){
            wyn+=calc(a,perm, sum, N, ind+1);
        }else{
            a[N[ind]-'0']--;
            wyn+=calc(a,(perm*((LL)a[N[ind]-'0']+1))/((LL)sum), sum-1, N, ind+1);
        }
        // cout<<wyn<<endl;
    }
    return wyn;
}

LL calc(LL a, string &N){
    vector<int> res(10);
    int sum=0;
    while(a>0){
        res[a%10]++;
        a/=10;
        sum++;
    }
    return calc(res, permutations(res,sum), sum, N, 0, 1);
}

void solve(){
    LL n;
    cin>>n;
    string N="";
    LL a=n;
    while(a>0){
        N=(char)((a%10)+'0')+N;
        a/=10;
    }
    vector<LL> wyn(10, 0);
    // cout<<calc(4,N)<<endl<<endl;
    // cout<<calc(2,N)<<endl<<endl;
    // int licz=0;
    for(auto x:tab){
        // if(calc(x.first, N)>0)cout<<x.first<<" "<<x.second<<endl;
        // licz++;
        wyn[x.second]+=calc(x.first, N);
        // if(calc(x.first,N)>0 && x.second==2)cout<<x.first<<" "<<calc(x.first,N)<<endl;
    }
    // cout<<licz<<endl;
    LL akt=1;
    while(akt<=n){
        wyn[1]++;
        akt=akt*10+1;
    }
    // for(int i=1;i<10;i++){
    //     wyn[i]+=calc(i, N);
    //     // cout<<i<<" "<<calc(i,N)<<endl;
    // }
    // cout<<calc(3,N)<<endl;
    wyn[0]=n;
    for(int i=1;i<10;i++){
        wyn[0]-=wyn[i];
    }
    for(int i=0;i<10;i++){
        cout<<wyn[i]<<" ";
    }
    cout<<'\n';

    return;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    sil.resize(50);
    sil[0] = 1;
    for(int i=1;i<50;i++)sil[i] = sil[i-1]*i;
    fun(0, 2);
    int t;
    cin>>t;
    while(t--)solve();
}