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

unordered_map<long long, int> memo;

int final_digit(long long x) {
    if(x < 10)
        return x;

    if(memo.count(x))
        return memo[x];

    long long original = x;
    long long prod = 1;

    while(x > 0) {
        int digit = x % 10;
        prod *= digit;
        x /= 10;
        if(prod == 0) break;
    }
    int res = final_digit(prod);
    memo[original] = res;
    return res;
}

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

    int t;
    cin >> t;

    while(t--) {
        int d;
        cin >> d;
        vector<int> cnt(10, 0);

        for (int i = 1; i <= d; i++) {
            int dig = final_digit(i);
            cnt[dig]++;
        }

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