#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ sum;

/* Variables and functions */
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, const char *argv[]) {
  int sum[10];
  int t;
  scanf("%d", &t);
  while (t--) {
    int num;
    scanf("%d", &num);
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= num; i++) {
      int k = i;
      while (k != 0) {
        sum[k % 10]++;
        k = k / 10;
      }
    }
    for (int i = 0; i < 9; i++)
      printf("%d ", sum[i]);
    printf("%d\n", sum[9]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x44(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x44(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x44(%rbp)
cmp    $0x0,%eax
je     1233 <main+0x103>
lea    0xe8f(%rip),%rdi
lea    -0x48(%rbp),%rsi
call   1050 <scanf@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
movl   $0x1,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x48(%rbp),%eax
jg     11ec <main+0xbc>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
je     11d9 <main+0xa9>
mov    -0x50(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x40(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x50(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x50(%rbp)
jmp    11a3 <main+0x73>
jmp    11de <main+0xae>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1191 <main+0x61>
movl   $0x0,-0x54(%rbp)
cmpl   $0x9,-0x54(%rbp)
jge    121f <main+0xef>
movslq -0x54(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xdf7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11f3 <main+0xc3>
mov    -0x1c(%rbp),%esi
lea    0xdde(%rip),%rdi
call   1030 <printf@plt>
jmp    1156 <main+0x26>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xebb(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
subl   $0x1,0x8(%rsp)
jae    1167 <main+0x37>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe92(%rip),%r14
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xe84(%rip),%rbp
lea    0xe81(%rip),%r13
jmp    1213 <main+0xe3>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%esi
mov    %rbp,%rdi
call   1030 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbp,%rdi
call   1030 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbp,%rdi
call   1030 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbp,%rdi
call   1030 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbp,%rdi
call   1030 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbp,%rdi
call   1030 <printf@plt>
mov    0x28(%rsp),%esi
mov    %rbp,%rdi
call   1030 <printf@plt>
mov    0x2c(%rsp),%esi
mov    %rbp,%rdi
call   1030 <printf@plt>
mov    0x30(%rsp),%esi
mov    %rbp,%rdi
call   1030 <printf@plt>
mov    0x34(%rsp),%esi
mov    %r13,%rdi
call   1030 <printf@plt>
subl   $0x1,0x8(%rsp)
jb     1156 <main+0x26>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    1190 <main+0x60>
mov    $0x1,%ecx
xchg   %ax,%ax
mov    %ecx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %edx,%rsi
imul   $0x66666667,%rsi,%rdx
mov    %rdx,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rdx
add    %edi,%edx
lea    (%rdx,%rdx,1),%edi
lea    (%rdi,%rdi,4),%edi
mov    %esi,%ebx
sub    %edi,%ebx
movslq %ebx,%rdi
addl   $0x1,0x10(%rsp,%rdi,4)
add    $0x9,%esi
cmp    $0x12,%esi
ja     1250 <main+0x120>
lea    0x1(%rcx),%edx
cmp    %eax,%ecx
mov    %edx,%ecx
jne    1240 <main+0x110>
jmp    1190 <main+0x60>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
br label %13
13: ; preds = %56, %2
%14 = load i32, i32* %7
%15 = add nsw i32 %14, -1
store i32 %15, i32* %7
%16 = icmp ne i32 %14, 0
br i1 %16, label %17, label %60
17: ; preds = %13
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%20 = call i32 @memset(i32* %19, i32 0, i32 40)
store i32 1, i32* %9
br label %21
21: ; preds = %40, %17
%22 = load i32, i32* %9
%23 = load i32, i32* %8
%24 = icmp sle i32 %22, %23
br i1 %24, label %25, label %43
25: ; preds = %21
%26 = load i32, i32* %9
store i32 %26, i32* %10
br label %27
27: ; preds = %30, %25
%28 = load i32, i32* %10
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32, i32* %10
%32 = srem i32 %31, 10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1
store i32 %36, i32* %34
%37 = load i32, i32* %10
%38 = sdiv i32 %37, 10
store i32 %38, i32* %10
br label %27
39: ; preds = %27
br label %40
40: ; preds = %39
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %21
43: ; preds = %21
store i32 0, i32* %11
br label %44
44: ; preds = %53, %43
%45 = load i32, i32* %11
%46 = icmp slt i32 %45, 9
br i1 %46, label %47, label %56
47: ; preds = %44
%48 = load i32, i32* %11
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %47
%54 = load i32, i32* %11
%55 = add nsw i32 %54, 1
store i32 %55, i32* %11
br label %44
56: ; preds = %44
%57 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 9
%58 = load i32, i32* %57
%59 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %58)
br label %13
60: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [10 x i32]* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%9 = load i32, i32* %4
%10 = add nsw i32 %9, -1
store i32 %10, i32* %4
%11 = icmp eq i32 %9, 0
br i1 %11, label %68, label %12
12: ; preds = %2
%13 = bitcast i32* %5 to i8*
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 0
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 9
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 1
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 2
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 3
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 4
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 5
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 6
%22 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 7
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 8
br label %24
24: ; preds = %12, %29
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%26 = call i32 @memset(i32* %14, i32 0, i32 40)
%27 = load i32, i32* %5
%28 = icmp slt i32 %27, 1
br i1 %28, label %29, label %53
29: ; preds = %65, %24
%30 = load i32, i32* %14
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %16
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %17
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %18
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %19
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %20
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %21
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %22
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %23
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %15
%49 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %4
%51 = add nsw i32 %50, -1
store i32 %51, i32* %4
%52 = icmp eq i32 %50, 0
br i1 %52, label %68, label %24
53: ; preds = %24, %65
%54 = phi i32 [ %66, %65 ], [ 1, %24 ]
br label %55
55: ; preds = %53, %55
%56 = phi i32 [ %54, %53 ], [ %62, %55 ]
%57 = srem i32 %56, 10
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %58
%60 = load i32, i32* %59
%61 = add nsw i32 %60, 1
store i32 %61, i32* %59
%62 = sdiv i32 %56, 10
%63 = add i32 %56, 9
%64 = icmp ult i32 %63, 19
br i1 %64, label %65, label %55
65: ; preds = %55
%66 = add nuw i32 %54, 1
%67 = icmp eq i32 %54, %27
br i1 %67, label %29, label %53
68: ; preds = %29, %2
ret i32 0
}