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

using namespace std;

typedef long long int ll;

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    
    while (t--)
    {
        string str;
        cin >> str;
        
        int max_digits = str.length();
        
        unordered_map<ll, ll> dp[20][2][2];
        int i, j;
        bool ignore = false;
        bool allow_any = true;
        for (i = 1; i <= 9; ++i)
        {
            if (!ignore && i > (str[0] - '0'))
                ignore = true;
            
            if (allow_any && i == (str[0] - '0'))
                allow_any = false;
            
            dp[1][ignore][allow_any][i] = 1;
        }
        
        bool started = false;
        for (i = 2; i <= max_digits; ++i)
        {
            for (int digit = 0; digit <= 9; ++digit)
            {
                for (int allow_any = 0; allow_any <= 1; ++allow_any)
                {
                    for (int ignore = 0; ignore <= 1; ++ignore)
                    {
                        bool new_ignore = !allow_any && (ignore || (digit > (str[i - 1] - '0')));
                        bool new_allow_any = !ignore && (allow_any || digit < (str[i - 1] - '0'));
                        
                        for (auto& p : dp[i - 1][ignore][allow_any])
                        {
                            ll new_product = p.first * digit;
                            
                            dp[i][new_ignore][new_allow_any][new_product] += p.second;
                        }
                    }
                }
            }
        }
        
        vector<ll> res(10, 0);
        ll mul;
        for (i = 1; i <= max_digits; ++i)
        {
            for (const auto& p : dp[i][0][1])
            {
                mul = multiplicative_digital_root(p.first);
                res[mul] += p.second;
            }
            
            for (const auto& p : dp[i][0][0])
            {
                mul = multiplicative_digital_root(p.first);
                res[mul] += p.second;
            }
            
            if (i != str.length())
            {
                for (j = 0; j <= 1; ++j)
                {
                    for (const auto& p : dp[i][1][j])
                    {
                        mul = multiplicative_digital_root(p.first);
                        res[mul] += p.second;
                    }
                }
            }
        }
        
        for (i = 0; i < 10; ++i)
        {
            cout << res[i] << " ";
        }
        cout << "\n";
    }

    return 0;
}