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
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define BOOST ios_base::sync_with_stdio(0), cin.tie(0)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

struct node{
	ll x;
	int y;
	int c;
	ll denom;
	int dic[10];
};

vector<node> t;
ll ans[10];
ll fac[20];

ll prodig(ll x){
	if(x == 0) return 0;
	ll res = 1;
	while(x){
		res *= x%10;
		x /= 10;
	}
	return res;
}

void go(ll x){
	ll y = x;
	while(y >= 10) y = prodig(y);
	if(y == 0) return;

	node res = {};
	res.x = x, res.y = y, res.denom = 1;
	while(x){
		res.dic[x%10]++;
		x /= 10;
		res.c++;
	}
	for(int i=1; i<10; i++){
		res.denom *= fac[res.dic[i]];
	}
	t.pb(res);
}

void rec(ll x, int c, int dig){
	if(dig == 10){
		go(x);
		return;
	}
	for(int i=0; i<=18-c; i++){
		rec(x, c + i, dig+1);
		x = x * 10 + dig;
	}
}

void f(ll n){
	for(int i=0; i<10; i++) ans[i] = 0;
	vector<int> v;
	while(n){
		v.pb(n % 10);
		n /= 10;
	}
	reverse(all(v));
	int s = v.size();

	for(auto it : t){
		if(s > it.c){
			ans[it.y] += fac[it.c]/it.denom;
			continue;
		}
		if(s < it.c){
			continue;
		}

		int c = it.c;
		ll denom = it.denom;
		int dic[10];
		for(int i=0; i<10; i++) dic[i] = it.dic[i];
		
		for(int j=0; j<s; j++){
			c--;
			for(int k=1; k<v[j]; k++){
				if(!dic[k]) continue;

				denom /= dic[k];
				dic[k]--;

				ans[it.y] += fac[c]/denom;

				dic[k]++;
				denom *= dic[k];
			}
			if(!dic[v[j]]) break;
			denom /= dic[v[j]];
			dic[v[j]]--;
		}
	}
}

int main(){
	BOOST;
	fac[0] = 1;
	for(int i=1; i<20; i++) fac[i] = fac[i-1] * i;
	rec(0, 0, 1);
	int q; cin >> q;
	while(q--){
		ll n; cin >> n;
		f(n+1);
		for(int i=1; i<10; i++){
			n -= ans[i];
		}
		ans[0] = n;
		for(int i=0; i<10; i++){
			cout << ans[i] << " ";
		}
		cout << "\n";
	}
}