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

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#ifdef LOCAL
auto operator<<(auto& o, auto x) -> decltype(x.first, o);
auto operator<<(auto& o, auto x) -> decltype(x.end(), o) {
  o << "{";
  for (int i = 0; auto y : x) o << ", " + !i++ * 2 << y;
  return o << "}"; }
auto operator<<(auto& o, auto x) -> decltype(x.first, o) {
  return o << "(" << x.first << ", " << x.second << ")"; }
void __print(auto... x) { ((cerr << x << " "), ...) << endl; }
#define debug(x...) __print("[" #x "]:", x)
#else
#define debug(...) 2137
#endif

#include <ext/pb_ds/assoc_container.hpp>
struct chash {
	const uint64_t C = ll(4e18 * acos(0)) | 71;
	ll operator()(ll x) const { return __builtin_bswap64(x*C); }
};
using M = __gnu_pbds::gp_hash_table<ll, ll, chash>;

const int D = 18;
M dp[D + 1][10], m;
vector<pair<ll, ll>> v[D + 1][10];
array<ll, 10> wyn[D + 1];
ll pot[D + 1];

ll f(ll x) {
  ll odp = x ? 1 : 0;
  while (x) odp *= x % 10, x /= 10;
  return odp;
}

void solve() {
  ll n;
  cin >> n;
  bool b1 = 0, b2 = 0;
  if (n == 1'000'000'000'000'000'000ll) b1 = 1, n--;
  if (n == 999'999'999'999'999'999ll) b2 = 1, n--;
  string s = to_string(n + 1);
  auto odp = wyn[sz(s) - 1];
  ll il = 1;
  rep(i, 0, sz(s)) {
    int d = s[i] - '0';
    if (d > 0) {
      for (auto [x, y] : v[sz(s) - i][d - 1]) {
        odp[m[x * il]] += y;
      }
      if (i == 0) odp[0] -= pot[sz(s) - 1 - i];
    }
    il *= d;
  }
  if (b1) odp[0]++;
  if (b2) odp[0]++;
  rep(i, 0, 10) cout << odp[i] << " \n"[i == 9];
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  rep(i, 0, 10) dp[0][i][1] = 1;
  rep(i, 0, D) rep(j, 0, 10) {
    if (j) for (auto [x, y] : dp[i + 1][j - 1]) dp[i + 1][j][x] = y;
    for (auto [x, y] : dp[i][9]) dp[i + 1][j][x * j] += y;
    v[i + 1][j] = {dp[i + 1][j].begin(), dp[i + 1][j].end()};
  }
  for (auto [i, x] : dp[D][9]) {
    ll j = i;
    while (j != f(j)) j = f(j);
    m[i] = j;
  }
  pot[0] = 1;
  rep(i, 1, D + 1) pot[i] = pot[i - 1] * 10;
  rep(i, 1, D + 1) {
    rep(j, 0, 10) wyn[i][j] += wyn[i - 1][j];
    for (auto [j, x] : dp[i][9]) wyn[i][m[j]] += x;
    wyn[i][0] -= pot[i - 1];
  }
  int t;
  cin >> t;
  while (t--) solve();
}