#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 *);
int main() {
  int t, r, c = 0, N, n;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    c = 0;
    scanf("%d", &n);
    N = n;
    while (N) {
      r = N % 10;
      if (r != 0 && n % r == 0)
        c++;
      N = N / 10;
    }
    printf("%d\n", c);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xec3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e1 <main+0xc1>
movl   $0x0,-0x10(%rbp)
lea    0xe99(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c4 <main+0xa4>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b1 <main+0x91>
mov    -0x18(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%edx
jne    11b1 <main+0x91>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
jmp    1176 <main+0x56>
mov    -0x10(%rbp),%esi
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114d <main+0x2d>
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
push   %rax
lea    0xece(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
cmpl   $0x0,(%rsp)
jle    11c8 <main+0xa8>
xor    %r13d,%r13d
lea    0xeb2(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xea9(%rip),%r12
jmp    1172 <main+0x52>
nopl   0x0(%rax)
mov    %r12,%rdi
call   1030 <printf@plt>
add    $0x1,%r13d
cmp    (%rsp),%r13d
jge    11c8 <main+0xa8>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%ecx
mov    $0x0,%esi
test   %ecx,%ecx
je     1160 <main+0x40>
xor    %esi,%esi
mov    %ecx,%edi
jmp    119a <main+0x7a>
add    $0x9,%edi
cmp    $0x12,%edi
mov    %ebx,%edi
jbe    1160 <main+0x40>
movslq %edi,%rbp
imul   $0x66666667,%rbp,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebp
je     1190 <main+0x70>
mov    %ecx,%eax
cltd
idiv   %ebp
cmp    $0x1,%edx
adc    $0x0,%esi
jmp    1190 <main+0x70>
xor    %eax,%eax
add    $0x8,%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"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %7
br label %9
9: ; preds = %38, %0
%10 = load i32, i32* %7
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %41
13: ; preds = %9
store i32 0, i32* %4
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%15 = load i32, i32* %6
store i32 %15, i32* %5
br label %16
16: ; preds = %32, %13
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %35
19: ; preds = %16
%20 = load i32, i32* %5
%21 = srem i32 %20, 10
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = load i32, i32* %6
%26 = load i32, i32* %3
%27 = srem i32 %25, %26
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %32
32: ; preds = %29, %24, %19
%33 = load i32, i32* %5
%34 = sdiv i32 %33, 10
store i32 %34, i32* %5
br label %16
35: ; preds = %16
%36 = load i32, i32* %4
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %35
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %9
41: ; preds = %9
ret i32 0
}

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