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
#!/usr/bin/env python3

import sys


def main():
    T = int(input())
    ngames = [int(x) for x in input().split()]

    ngames_asc = sorted(ngames)
    last = ngames_asc[T - 1]
    if last >= 5_000_000:
        print("?")
        return

    counts = [0] * 10

    lookup = [0] * (last + 1)
    for i in range(10):
        lookup[i] = i

    counts_at = {}
    t = 0
    for x in range(1, last + 1):
        v = x
        d = 1
        while v > 0:
            d *= v % 10
            v //= 10
        lookup[x] = lookup[d]
        counts[lookup[x]] += 1

        if x == ngames_asc[t]:
            counts_at[x] = list(counts)
            t += 1

    for x in ngames:
        print(*counts_at[x])


if __name__ == "__main__":
    if len(sys.argv) == 2:
        sys.stdin = open(sys.argv[1])
    main()