#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 t, ans, rem;
  long long int num, temp;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld", &num);
    temp = num;
    ans = 0;
    {
      do {
        rem = num % 10;
        num = num / 10;
        if (rem != 0) {
          if (temp % rem == 0)
            ans++;
        }
      } while (num != 0);
      printf("%d\n", ans);
    }
  }
  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>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11ee <main+0xce>
lea    0xea7(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11ca <main+0xaa>
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    11c5 <main+0xa5>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ca <main+0xaa>
jmp    11cf <main+0xaf>
cmpq   $0x0,-0x18(%rbp)
jne    1176 <main+0x56>
mov    -0xc(%rbp),%esi
lea    0xe24(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xecc(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    1157 <main+0x37>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xea5(%rip),%r14
lea    0x8(%rsp),%r15
movabs $0x6666666666666667,%r13
66 66 66
lea    0xe94(%rip),%r12
jmp    1194 <main+0x74>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,0x8(%rsp)
mov    %r12,%rdi
call   1030 <printf@plt>
subl   $0x1,0x4(%rsp)
jb     1147 <main+0x27>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%r8
mov    %r8,%rdi
xor    %esi,%esi
jmp    11cc <main+0xac>
nopl   (%rax)
mov    %r8,%rax
cqto
idiv   %rcx
cmp    $0x1,%rdx
adc    $0x0,%esi
add    $0x9,%rdi
cmp    $0x12,%rdi
mov    %rbx,%rdi
jbe    1180 <main+0x60>
mov    %rdi,%rax
imul   %r13
mov    %rdx,%rbx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rbx
add    %rax,%rbx
lea    (%rbx,%rbx,1),%rax
lea    (%rax,%rax,4),%rax
mov    %rdi,%rcx
sub    %rax,%rcx
test   %ecx,%ecx
je     11bf <main+0x9f>
mov    %r8,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    11b0 <main+0x90>
mov    %r8d,%eax
xor    %edx,%edx
div    %ecx
jmp    11b8 <main+0x98>

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

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