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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, ll, bool> dt;

static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();

static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += FIXED_RANDOM;
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}

struct hash_tuple { 
  
    template <class T1, class T2, class T3> 
  
    size_t operator()( 
        const tuple<T1, T2, T3>& x) 
        const
    { 
        return splitmix64(get<0>(x)) ^ splitmix64(get<1>(x)) ^ splitmix64(get<2>(x)); 
    } 
}; 

unordered_map<dt, map<int, ll>, hash_tuple> mem;
string lm;

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

    if (res < 10) return res;
    return exec(res);
}

map<int, ll> dp2(int leftl, ll prod, bool start) {
    dt ctup = make_tuple(leftl, prod, start);

    if (mem.find(ctup) != mem.end()) {
        return mem[ctup];
    }

    if (leftl == 0) {
        if (!start) {
            return {};
        }

        map<int, ll> mp;
        mp[exec(prod)] = 1;
        return mp;
    }

    map<int, ll> res;
    for (int d=0; d<=9; ++d) {
        bool nst = false;
        ll nprd = 1;

        if (!start && d == 0) {
            nst = false;
            nprd = prod;
        } else {
            nst = true;
            nprd = prod * d;
        }

        for (auto u : dp2(leftl-1, nprd, nst)) {
            res[u.first] += u.second;
        }
    }

    return mem[ctup] = res;
}

map<int, ll> dp(int pos, ll prod, bool tg, bool start) {
    if (pos == (int)lm.size()) {
        if (!start) {
            return {};
        }

        map<int, ll> mp;
        mp[exec(prod)] = 1;
        return mp;
    }

    if (!tg) {
        return dp2((int)lm.size() - pos, prod, start);
    }

    map<int, ll> res;
    ll mx = lm[pos]-'0';

    for (ll d=0; d<=mx; ++d) {
        bool ntg = d == mx;
        bool nst;
        ll npr = 1;
        if (!start && d == 0) {
            nst = false;
            npr = 1;
        } else {
            nst = true;
            npr = prod * d;
        }
        map<int, ll> nw = dp(pos+1, npr, ntg, nst);
        for (auto u : nw) {
            res[u.first] += u.second;
        }
    }

    return res;
}

void solve() {
    ll n; cin>>n;
    lm = to_string(n);

    map<int, ll> res = dp(0, 1, true, false);

    for (int i=0; i<=9; ++i) {
        cout<<res[i]<<" ";
    } cout<<"\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t=1; cin>>t;
    while (t--) solve();
}