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
157
158
159
160
161
#include <bits/stdc++.h>
using namespace std;
unsigned long long large_number=1e18;
const int SIZE=65423;

int calc[SIZE];
long long dp[20][10][SIZE];
long long dp_smpl[20][10][10];
map<long long,int> trans;
vector<long long> P;
long long tab[10];
long long prefix[18][10];

int CALC(long long W){
    long long W2;
    while(W>9){
        W2=1;
        while(W){W2*=(W%10);W/=10;}
        W=W2;
    }
    return W;
}

void PRE(){

    long long m2=1,m3,m5,m7;
    for(int i=0;i<=54;i++){
        m3=1;
        for(int j=0;j<=36;j++){
            m5=1;
            for(int h=0;h<=18;h++){
                m7=1;
                for(int g=0;g<=18;g++){
                    P.push_back(m2*m3*m5*m7);
                    m7*=7;
                    if(m2*m3*m5*m7>=large_number){break;}
                }
                m5*=5;
                if(m2*m3*m5>=large_number){break;}
            }
            m3*=3;
            if(m2*m3>=large_number){break;}
        }
        m2*=2;
    }
    P.push_back(0);
    sort(P.begin(),P.end());
    for(int i=0;i<SIZE;i++){trans[P[i]]=i;}
    int ind;

    for(long long i=0;i<10;i++){dp[1][i][trans[i]]=1;}

    for(int l=2;l<18;l++){
        for(int z=1;z<10;z++){
            for(int m=0;m<SIZE;m++){
                if(!dp[l-1][z][m]){continue;}
                for(long long i=0;i<10;i++){
                   ind=trans[P[m]*i];
                   dp[l][z][ind]+=dp[l-1][z][m];

                }
            }
        }
    }

    for(int m=0;m<SIZE;m++){
        ind=CALC(P[m]);
        calc[m]=ind;
        for(int z=0;z<10;z++){
            for(int l=1;l<18;l++){
                dp_smpl[l][z][ind]+=dp[l][z][m];

            }
        }
    }

    for(int l=1;l<18;l++){
        for(int x=0;x<10;x++){
            for(int z=0;z<10;z++){
                prefix[l][x]+=dp_smpl[l][z][x];
            }

            prefix[l][x]+=prefix[l-1][x];
        }
    }
}

void CLEAR(){
    for(int i=0;i<10;i++){tab[i]=0;}
}


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

    PRE();

    int N;
    long long a;

    cin>>N;
    //N=250;

    for(int i=0;i<N;i++){

    cin>>a;
    //a=999999999999999999;
    CLEAR();
    
    if(a<100){
        for(int i=1;i<=a;i++){tab[CALC(i)]++;}
        for(int i=0;i<10;i++){cout<<tab[i]<<' ';}cout<<'\n';
        continue;
    }
    
    if(a==1e18){a--;tab[0]++;tab[CALC(a)]++;}
    else if(a==1e18-1){tab[CALC(a)]++;}
    else a++;

    long long p,res;
    int ind;
    int d=to_string(a).size();

    for(int i=0;i<10;i++){tab[i]=prefix[d-1][i];}//1
    tab[0]--;
    p=to_string(a)[0]-48;

    for(int i=1;i<p;i++){
        for(int j=0;j<10;j++){
            tab[j]+=dp_smpl[d][i][j]; //2
        }
    }

    int y;
    res=p;
    for(int x=1;x<d;x++){
        y=d-x;
        p=1;
        for(int i=0;i<y-1;i++){p*=10ll;}
        tab[0]+=p;

        p=to_string(a)[x]-48;
        for(int m=0;m<SIZE;m++){
            if(P[m]*res>=large_number||P[m]*res<0){break;}
            ind=trans[P[m]*res];
            for(int z=1;z<p;z++){
                tab[calc[ind]]+=dp[y][z][m];
            }
        }
        res*=p;

    }

    for(int i=0;i<10;i++){cout<<tab[i]<<' ';}cout<<'\n';

    }


return 0;}