#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int cases;
  scanf("%d", &cases);
  for (int a = 1; a <= cases; a++) {
    unsigned long int num;
    scanf("%lu", &num);
    int count = 0;
    while (num) {
      int x = num % 10;
      if (x > 0) {
        if (num % x == 0)
          count++;
      }
      num /= 10;
    }
    printf("%i\n", count);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11ee <main+0xce>
lea    0xea8(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d1 <main+0xb1>
mov    -0x18(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %edx,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    11ba <main+0x9a>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    11b5 <main+0x95>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ba <main+0x9a>
mov    -0x18(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x18(%rbp)
jmp    116d <main+0x4d>
mov    -0x1c(%rbp),%esi
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1148 <main+0x28>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1206 <main+0xe6>
mov    $0x1,%r13d
lea    0xeaa(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xea2(%rip),%r12
movabs $0xcccccccccccccccd,%rbp
cc cc cc
jmp    119b <main+0x7b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rdi,0x10(%rsp)
mov    %r12,%rdi
call   1030 <printf@plt>
lea    0x1(%r13),%eax
cmp    0xc(%rsp),%r13d
mov    %eax,%r13d
jge    1206 <main+0xe6>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%rcx
mov    $0x0,%esi
test   %rcx,%rcx
je     1185 <main+0x65>
xor    %esi,%esi
jmp    11d8 <main+0xb8>
nopl   0x0(%rax,%rax,1)
mov    %rcx,%rax
xor    %edx,%edx
div    %rbx
cmp    $0x1,%rdx
adc    $0x0,%esi
cmp    $0x9,%rcx
mov    %rdi,%rcx
jbe    1180 <main+0x60>
mov    %rcx,%rax
mul    %rbp
mov    %rdx,%rdi
shr    $0x3,%rdi
lea    (%rdi,%rdi,1),%rax
lea    (%rax,%rax,4),%rax
mov    %rcx,%rbx
sub    %rax,%rbx
je     11cf <main+0xaf>
mov    %rcx,%rax
shr    $0x20,%rax
jne    11c0 <main+0xa0>
mov    %ecx,%eax
xor    %edx,%edx
div    %ebx
jmp    11c8 <main+0xa8>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%lu\00"
@.str.2 = [4 x i8] c"%i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 1, i32* %3
br label %8
8: ; preds = %39, %0
%9 = load i32, i32* %3
%10 = load i32, i32* %2
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %42
12: ; preds = %8
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %4)
store i32 0, i32* %5
br label %14
14: ; preds = %33, %12
%15 = load i64, i64* %4
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %36
17: ; preds = %14
%18 = load i64, i64* %4
%19 = urem i64 %18, 10
%20 = trunc i64 %19 to i32
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %17
%24 = load i64, i64* %4
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = urem i64 %24, %26
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %29, %23
br label %33
33: ; preds = %32, %17
%34 = load i64, i64* %4
%35 = udiv i64 %34, 10
store i64 %35, i64* %4
br label %14
36: ; preds = %14
%37 = load i32, i32* %5
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %8
42: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%lu\00"
@.str.2 = [4 x i8] c"%i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = bitcast i32* %1 to i8*
%4 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 1
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = bitcast i64* %2 to i8*
br label %10
9: ; preds = %30, %0
ret i32 0
10: ; preds = %7, %30
%11 = phi i32 [ 1, %7 ], [ %33, %30 ]
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%13 = load i64, i64* %2
%14 = icmp eq i64 %13, 0
br i1 %14, label %30, label %15
15: ; preds = %10, %26
%16 = phi i32 [ %27, %26 ], [ 0, %10 ]
%17 = phi i64 [ %19, %26 ], [ %13, %10 ]
%18 = urem i64 %17, 10
%19 = udiv i64 %17, 10
%20 = icmp eq i64 %18, 0
br i1 %20, label %26, label %21
21: ; preds = %15
%22 = urem i64 %17, %18
%23 = icmp eq i64 %22, 0
%24 = zext i1 %23 to i32
%25 = add nsw i32 %16, %24
br label %26
26: ; preds = %21, %15
%27 = phi i32 [ %16, %15 ], [ %25, %21 ]
%28 = icmp ult i64 %17, 10
br i1 %28, label %29, label %15
29: ; preds = %26
store i64 %19, i64* %2
br label %30
30: ; preds = %29, %10
%31 = phi i32 [ %27, %29 ], [ 0, %10 ]
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i32 %11, 1
%34 = load i32, i32* %1
%35 = icmp slt i32 %11, %34
br i1 %35, label %10, label %9
}