#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 /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int strtol(char *, char **, int);
int main(int argc, char const *argv[]) {
  int t;
  scanf("%d\n", &t);
  char n[10];
  for (int i_t = 0; i_t < t; i_t++) {
    scanf("%s", &n);
    int n_value;
    char *endptr;
    char n_copy[10];
    strcpy(n_copy, n);
    n_value = strtol(n_copy, &endptr, 10);
    int count = 0;
    int curr_char;
    for (int i = 0; i < strlen(n); i++) {
      curr_char = (int)n[i] - 48;
      if (curr_char == 0)
        continue;
      if (n_value % curr_char == 0) {
        count++;
      }
    }
    printf("%d\n", count);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1250 <main+0x100>
lea    0xe72(%rip),%rdi
lea    -0x1e(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    -0x3a(%rbp),%rdi
lea    -0x1e(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x3a(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    -0x1e(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
cmp    %ecx,%eax
jge    1233 <main+0xe3>
movslq -0x48(%rbp),%rax
movsbl -0x1e(%rbp,%rax,1),%eax
sub    $0x30,%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    1207 <main+0xb7>
jmp    1225 <main+0xd5>
mov    -0x28(%rbp),%eax
cltd
idivl  -0x44(%rbp)
cmp    $0x0,%edx
jne    1220 <main+0xd0>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1225 <main+0xd5>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11cd <main+0x7d>
mov    -0x40(%rbp),%esi
lea    0xdc3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117f <main+0x2f>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe9b(%rip),%rdi
xor    %r12d,%r12d
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmpl   $0x0,(%rsp)
jle    121c <main+0xcc>
lea    0x6(%rsp),%rbx
lea    0x1e(%rsp),%r15
jmp    11a8 <main+0x58>
nopl   0x0(%rax,%rax,1)
lea    0xe69(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
add    $0x1,%r12d
cmp    (%rsp),%r12d
jge    121c <main+0xcc>
xor    %ebp,%ebp
lea    0xe53(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1190 <main+0x40>
xor    %r13d,%r13d
xor    %ebp,%ebp
jmp    1203 <main+0xb3>
xchg   %ax,%ax
add    $0x1,%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%r13
jge    1190 <main+0x40>
movsbl 0x6(%rsp,%r13,1),%ecx
add    $0xffffffd0,%ecx
je     11f0 <main+0xa0>
mov    %r14d,%eax
cltd
idiv   %ecx
cmp    $0x1,%edx
adc    $0x0,%ebp
jmp    11f0 <main+0xa0>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = alloca i8*
%6 = alloca [10 x i8]
%7 = bitcast i32* %3 to i8*
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = bitcast i8** %5 to i8*
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
br label %16
15: ; preds = %23, %2
ret i32 0
16: ; preds = %12, %23
%17 = phi i32 [ 0, %12 ], [ %26, %23 ]
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), [10 x i8]* %4)
%19 = call i32 @strcpy(i8* %14, i8* %9)
%20 = call i32 @strtol(i8* %14, i8** %5, i32 10)
%21 = call i32 @strlen(i8* %9)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %42, %16
%24 = phi i32 [ 0, %16 ], [ %43, %42 ]
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = add nuw nsw i32 %17, 1
%27 = load i32, i32* %3
%28 = icmp slt i32 %26, %27
br i1 %28, label %16, label %15
29: ; preds = %16, %42
%30 = phi i64 [ %44, %42 ], [ 0, %16 ]
%31 = phi i32 [ %43, %42 ], [ 0, %16 ]
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %30
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = add nsw i32 %34, -48
%36 = icmp eq i32 %35, 0
br i1 %36, label %42, label %37
37: ; preds = %29
%38 = srem i32 %20, %35
%39 = icmp eq i32 %38, 0
%40 = zext i1 %39 to i32
%41 = add nsw i32 %31, %40
br label %42
42: ; preds = %37, %29
%43 = phi i32 [ %31, %29 ], [ %41, %37 ]
%44 = add nuw nsw i64 %30, 1
%45 = call i32 @strlen(i8* %9)
%46 = sext i32 %45 to i64
%47 = icmp slt i64 %44, %46
br i1 %47, label %29, label %23
}