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
#include <bits/stdc++.h>
#define e using u=ostream;template<class a,class b>u&operator<<(u&o,pair<a,b>&x)
using namespace std;e;u&operator<<(u&o,string&s){return o<<s.c_str();}template<
class t>auto operator<<(u&o,t&x)->decltype(x.end(),o){o<<'{';int i=2;for(auto y:
x)o<<", "+i<<y,i=0;return o<<'}';}e{return o<<'('<<x.first<<", "<<x.second<<')';}
#ifdef DEBUG
#define LOG(x...)cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...)<<'\n';}(x)
#else
#define LOG(...)
#endif
#define ff first
#define ss second
#define ll long long

ll product(ll n) {
    ll res = 1;
    if (n == 0) {
        return 0;
    }
    while (n > 0 && res != 0) {
        ll d = n % 10;
        res *= d;
        n /= 10;
    }
    return res;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin >> t;
	while (t--) {
		ll n;
		cin >> n;
		vector <int> v(10);
		for (int i = 1; i <= n; i++) {
			ll j = i;
			while (true) {
				ll k = product(j);
				if (k == j)
					break;
				j = k;
			}
			v[j]++;
		}
		for (int i = 0; i < 10; i++) {
			cout << v[i] << " ";
		}
		cout << "\n";
	}
}