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
#include <algorithm>
#include <array>
#include <iostream>
#include <tuple>
#include <utility>
#include <vector>
using ll = long long;

// Tail recursion, GCC does just generate a loop
inline constexpr int simulate(ll x) noexcept {
	if (x < 10) return x;
	
	ll prod = 1;
	while (x > 0 && prod > 0) {
		prod *= x % 10;
		x /= 10;
	}
	
	return simulate(prod);
}

// (unused)
/*void solve(ll n) {
	int answers[10]{};
	for (ll x = 1; x <= n; ++x) {
		int digit = simulate(x);
		++answers[digit];
	}
	for (int i = 0; i < 10; ++i) {
		std::cout << answers[i] << ' ';
	}
	std::cout << '\n';
}*/

int main() {
	std::ios_base::sync_with_stdio(0); std::cin.tie(0);
	int t;
	std::cin >> t;
	
	std::vector<std::pair<ll, int>> sorted(t);
	for (int i = 0; i < t; ++i) {
		ll n;
		std::cin >> n;
		sorted[i] = {n, i};
	}
	
	std::sort(sorted.begin(), sorted.end());
	ll maxn = sorted.back().first;
	
	std::vector<std::array<ll, 10>> answers(t);
	
	std::array<ll, 10> counts{};
	
	int tt = 0;
	for (ll n = 1; n <= maxn; ++n) {
		int digit = simulate(n);
		++counts[digit];
		
		while (tt < t && sorted[tt].first == n) {
			answers[sorted[tt].second] = counts;
			++tt;
		}
	}
	
	for (int i = 0; i < t; ++i) {
		for (int j = 0; j < 10; ++j) {
			std::cout << answers[i][j] << ' ';
		}
		std::cout << '\n';
	}
}