#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;
  scanf("%d", &t);
  for (int a0 = 0; a0 < t; a0++) {
    int n;
    int count = 0;
    scanf("%d", &n);
    for (int i = n; i > 0; i = (int)(i / 10)) {
      if ((i % 10) != 0 && n % (i % 10) == 0)
        count++;
    }
    printf("%d\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
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ed <main+0xcd>
movl   $0x0,-0x14(%rbp)
lea    0xea0(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11d0 <main+0xb0>
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11b8 <main+0x98>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
mov    %edx,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b8 <main+0x98>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bd <main+0x9d>
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
jmp    116f <main+0x4f>
mov    -0x14(%rbp),%esi
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <main+0x26>
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    11cb <main+0xab>
xor    %r13d,%r13d
lea    0x4(%rsp),%r15
mov    $0xcccccccd,%r14d
lea    0xeaa(%rip),%r12
jmp    1172 <main+0x52>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <printf@plt>
add    $0x1,%r13d
cmp    (%rsp),%r13d
jge    11cb <main+0xab>
lea    0xe87(%rip),%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%ebx
mov    $0x0,%esi
test   %ebx,%ebx
jle    1160 <main+0x40>
xor    %esi,%esi
mov    %ebx,%ecx
jmp    11a7 <main+0x87>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0xa,%ecx
mov    %ebp,%ecx
jb     1160 <main+0x40>
mov    %ecx,%ebp
imul   %r14,%rbp
shr    $0x23,%rbp
lea    0x0(%rbp,%rbp,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ecx,%edi
sub    %eax,%edi
je     11a0 <main+0x80>
mov    %ebx,%eax
cltd
idiv   %edi
cmp    $0x1,%edx
adc    $0x0,%esi
jmp    11a0 <main+0x80>
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
store i32 0, i32* %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
br label %8
8: ; preds = %38, %0
%9 = load i32, i32* %3
%10 = load i32, i32* %2
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %41
12: ; preds = %8
store i32 0, i32* %5
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%14 = load i32, i32* %4
store i32 %14, i32* %6
br label %15
15: ; preds = %32, %12
%16 = load i32, i32* %6
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %35
18: ; preds = %15
%19 = load i32, i32* %6
%20 = srem i32 %19, 10
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %18
%23 = load i32, i32* %4
%24 = load i32, i32* %6
%25 = srem i32 %24, 10
%26 = srem i32 %23, %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %31
31: ; preds = %28, %22, %18
br label %32
32: ; preds = %31
%33 = load i32, i32* %6
%34 = sdiv i32 %33, 10
store i32 %34, i32* %6
br label %15
35: ; preds = %15
%36 = load i32, i32* %5
%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* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %8
41: ; preds = %8
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 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = bitcast i32* %2 to i8*
br label %10
9: ; preds = %15, %0
ret i32 0
10: ; preds = %7, %15
%11 = phi i32 [ 0, %7 ], [ %18, %15 ]
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %32, %10
%16 = phi i32 [ 0, %10 ], [ %33, %32 ]
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i32 %11, 1
%19 = load i32, i32* %1
%20 = icmp slt i32 %18, %19
br i1 %20, label %10, label %9
21: ; preds = %10, %32
%22 = phi i32 [ %25, %32 ], [ %13, %10 ]
%23 = phi i32 [ %33, %32 ], [ 0, %10 ]
%24 = urem i32 %22, 10
%25 = udiv i32 %22, 10
%26 = icmp eq i32 %24, 0
br i1 %26, label %32, label %27
27: ; preds = %21
%28 = srem i32 %13, %24
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = add nsw i32 %23, %30
br label %32
32: ; preds = %27, %21
%33 = phi i32 [ %23, %21 ], [ %31, %27 ]
%34 = icmp ult i32 %22, 10
br i1 %34, label %15, label %21
}