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
#include<bits/stdc++.h>
using namespace std;
int results[1000001][10];
int digitsOfNumbers[1000001];
long long products[1000001];
int zabawa(int n)
{
    int ncopy = n;
    if(n<10)
        return n;
    int newNumber=1;
    while(n>0)
    {
        newNumber *= n%10;
        n/=10;
    }
    products[ncopy] = newNumber;
    digitsOfNumbers[ncopy] = zabawa(newNumber);
    return digitsOfNumbers[ncopy];
}

int fastZabawa(long long n)
{
    if(n<10)
        return n;
    if(n<1000000)
        return digitsOfNumbers[n];
    //  if(n==2111126)
    //  cerr<<n/1000000<<" products[n/1e6]="<<products[n / 1000000]<<" products[n mod 1e6]="<<products[n % 1000000]<<endl;
    if(n%1000000<100000)
        return 0;
    return fastZabawa(products[n / 1000000] * products[n % 1000000]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    int t,n;
    cin>>t;
    // cerr<<"generating"<<endl;
    for(int i=1;i<=1000000;i++)
    {
        results[i][zabawa(i)]++;
    }
    // cerr<<"tu"<<endl;
    for(int i=1;i<=1000000;i++)
    {
        for(int j=0;j<10;j++)
            results[i][j]+=results[i-1][j];
    }
    for(int i=0;i<10;i++)
    {
        products[i]=i;
    }
    // cerr<<"end of gen"<<endl;
    // cerr<<fastZabawa(33333333333ll)<<endl;
    for(;t>0;t--)
    {
        cin>>n;
        if(n<=1000000)
        {
            for(int i=0;i<10;i++)
                cout<<results[n][i]<<" ";
            cout<<endl;
        }
        else
        {
            int result[10];
            for(int i=0;i<10;i++)
                result[i]=results[1000000][i];
            for(int i=1000001;i<=n;i++)
            {
                // if(i==1111111)
                //     cerr<<i<<" sssss "<<fastZabawa(i)<<endl;
                result[fastZabawa(i)]++;
            }
            for(int i=0;i<10;i++)
                cout<<result[i]<<" ";
            cout<<endl;
        }
    }
    return 0;
}