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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
//fast
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define all(x) x.begin(),x.end()
#define rep(n) for (int i = 0 ; i<n ; i++)
#define pb push_back

struct hasz{
    size_t operator()(ll x) const{
        return x^587125926991951LL;
    }
};

unordered_map<ll,ll,hasz> odp;


void solve(){
    string n;
	cin >> n;
	unordered_map<ll,ll,hasz> xd;
	bool start = 1;
	ll ilo = 1;
	for (char c : n){
		unordered_map<ll,ll,hasz> nowy;
		for (auto x : xd){
			if (x.first==-1){
				for (int j = 1 ; j<=9 ; j++){
					nowy[x.first*j*-1]+=x.second;
				}
				nowy[-1]++;
				continue;
			}
			for (int j = 0 ; j<=9 ; j++){
				nowy[x.first*j]+=x.second;
			}
		}
		for (int j = 0 ; j<c-'0' ; j++){
			if (j==0 && start) nowy[-1]++;
			else nowy[j*ilo]++;
		}
		ilo*=c-'0';
		swap(nowy,xd);
		start = 0;
	}
	ll ile[10] = {0};
	ll xdd = 1;
	for (char c : n){
		xdd*=c-'0';
	}
	xd[xdd]++;
	for (auto x : xd){
		if (x.first==-1) continue;
		ile[odp[x.first]]+=x.second;
	}
	rep(10) cout << ile[i] << ' ';
	cout << '\n';
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    cin >> t;
	string n = "1000000000000000000";
	unordered_set<ll> xd;
	bool start = 1;
	ll ilo = 1;
	for (char c : n){
		unordered_set<ll> nowy;
		for (auto x : xd){
			if (x==-1){
				for (int j = 1 ; j<=9 ; j++){
					nowy.insert(x*j*-1);
				}
				nowy.insert(-1);
				continue;
			}
			for (int j = 0 ; j<=9 ; j++){
				nowy.insert(x*j);
			}
		}
		for (int j = 0 ; j<c-'0' ; j++){
			if (j==0 && start) nowy.insert(-1);
			else nowy.insert(j*ilo);
		}
		ilo*=c-'0';
		swap(nowy,xd);
		start = 0;
	}
	ll xdd = 1;
	for (char c : n){
		xdd*=c-'0';
	}
	xd.insert(xdd);
	for (auto x : xd){
		if (x==-1) continue;
		ll y = x;
		while (y>9){
			ll ilo = 1;
			while (y>0){
				ilo*=y%10;
				y/=10;
			}
			y = ilo;
		}
		odp[x] = y;
	}
    rep(t) solve();
}