#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 */
scalar_t__ EOF;
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ scanf(char *, ...);
int main() {
  int n, i, p, num;
  char ar[9999];
  while (scanf("%d", &n) != EOF) {
    for (p = 1; p <= n; p++) {
      num = 0;
      for (i = 0; i < 9999; i++) {
        scanf("%c", &ar[i]);
        if (isdigit(ar[i]))
          num++;
        if (i > 0 && ar[i] == '\n')
          break;
      }
      printf("%d\n", num);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2730,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    0x2e8d(%rip),%rcx
cmp    (%rcx),%rax
je     122b <main+0xfb>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1226 <main+0xf6>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x270f,-0xc(%rbp)
jge    1209 <main+0xd9>
movslq -0xc(%rbp),%rax
lea    -0x2730(%rbp),%rsi
add    %rax,%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
movslq -0xc(%rbp),%rax
movsbl -0x2730(%rbp,%rax,1),%edi
ff
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11d2 <main+0xa2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11f6 <main+0xc6>
movslq -0xc(%rbp),%rax
movsbl -0x2730(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    11f6 <main+0xc6>
jmp    1209 <main+0xd9>
jmp    11fb <main+0xcb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1185 <main+0x55>
mov    -0x14(%rbp),%esi
lea    0xdf3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116b <main+0x3b>
jmp    1142 <main+0x12>
xor    %eax,%eax
add    $0x2730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2728,%rsp
lea    0xeb8(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x2e8d(%rip),%rcx
cmp    (%rcx),%rax
jne    1174 <main+0x44>
xor    %eax,%eax
add    $0x2728,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe88(%rip),%r13
jmp    119f <main+0x6f>
nopl   (%rax)
lea    0xe79(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
je     1160 <main+0x30>
cmpl   $0x0,0xc(%rsp)
jle    1180 <main+0x50>
mov    $0x1,%r15d
jmp    11cc <main+0x9c>
xchg   %ax,%ax
lea    0xe4f(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
lea    0x1(%r15),%eax
cmp    0xc(%rsp),%r15d
mov    %eax,%r15d
jge    1180 <main+0x50>
xor    %ebp,%ebp
xor    %eax,%eax
mov    %eax,%r14d
mov    %eax,%r12d
lea    (%rsp,%r12,1),%rbx
add    $0x10,%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movsbl 0x10(%rsp,%r12,1),%edi
call   1030 <isdigit@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0x1,%eax
test   %r14d,%r14d
je     11d0 <main+0xa0>
cmpb   $0xa,(%rbx)
je     11b0 <main+0x80>
lea    0x1(%r14),%eax
cmp    $0x270e,%r14d
jb     11d0 <main+0xa0>
jmp    11b0 <main+0x80>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.1 = [3 x i8] c"%c\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 i32
%6 = alloca [9999 x i8]
store i32 0, i32* %1
br label %7
7: ; preds = %55, %0
%8 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i64, i64* @EOF
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %56
11: ; preds = %7
store i32 1, i32* %4
br label %12
12: ; preds = %52, %11
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %55
16: ; preds = %12
store i32 0, i32* %5
store i32 0, i32* %3
br label %17
17: ; preds = %46, %16
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 9999
br i1 %19, label %20, label %49
20: ; preds = %17
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [9999 x i8], [9999 x i8]* %6, i64 0, i64 %22
%24 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [9999 x i8], [9999 x i8]* %6, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = call i64 @isdigit(i8 signext %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %20
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %34
34: ; preds = %31, %20
%35 = load i32, i32* %3
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %34
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [9999 x i8], [9999 x i8]* %6, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 10
br i1 %43, label %44, label %45
44: ; preds = %37
br label %49
45: ; preds = %37, %34
br label %46
46: ; preds = %45
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
store i32 %48, i32* %3
br label %17
49: ; preds = %44, %17
%50 = load i32, i32* %5
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %49
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %12
55: ; preds = %12
br label %7
56: ; preds = %7
ret i32 0
}

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