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
// Author: Bartek Knapik

#include <cstdio>

const int MAX_MEM = 10000000;
long long ans[10];
long long mem[MAX_MEM];
int t;
long long n;

long long mno(long long n)
{
    if (0 <= n && n <= 9)
        return n;
    
    if (n < MAX_MEM && mem[n] != -1LL)
        return mem[n];
    
    int n_ = (int) n;
    
    long long p = 1LL;
    while (n)
    {
        p *= (n % 10LL);
        n /= 10LL;
    }
    mem[n_] = mno(p);
    
    return mem[n_];
}

void solve()
{
    scanf("%lld", &n);
    for (int i = 0; i < 10; ++i) ans[i] = 0LL;
    for (long long i = 1; i <= n; ++i) ans[mno(i)]++;
    for (int i = 0; i < 10; ++i) printf("%lld%c", ans[i], i == 9 ? '\n' : ' ');
}

int main()
{
    scanf("%d", &t);
    for (int i = 0; i < MAX_MEM; ++i) mem[i] = -1LL;
    while (t--) solve();
    return 0;
}