#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 N, S, D, i, j, w, ans;
  scanf("%d", &D);
  for (j = 0; j < D; j++) {
    scanf("%d", &N);
    if (N == 0)
      break;
    w = 0;
    ans = 0;
    for (i = 0; i < N; i++) {
      scanf("%d", &S);
      if (S == 0) {
        ans += (i - w);
        w++;
      }
    }
    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    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11f1 <main+0xd1>
lea    0xea7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1171 <main+0x51>
jmp    11f1 <main+0xd1>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d4 <main+0xb4>
lea    0xe67(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    11c1 <main+0xa1>
mov    -0x14(%rbp),%eax
sub    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c6 <main+0xa6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1186 <main+0x66>
mov    -0x20(%rbp),%esi
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%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
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11d1 <main+0xb1>
xor    %r13d,%r13d
lea    0xeac(%rip),%rbx
lea    0x14(%rsp),%r15
xor    %ebp,%ebp
jmp    117d <main+0x5d>
nopl   (%rax)
xor    %ebp,%ebp
lea    0xe9a(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    0x10(%rsp),%ebp
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jge    11d1 <main+0xb1>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     11d1 <main+0xb1>
mov    %ebp,0x10(%rsp)
jle    1160 <main+0x40>
xor    %ebp,%ebp
xor    %r14d,%r14d
xor    %r12d,%r12d
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    %r12d,%eax
sub    %r14d,%eax
xor    %ecx,%ecx
cmpl   $0x0,0x14(%rsp)
sete   %cl
cmovne %r13d,%eax
add    %ecx,%r14d
add    %eax,%ebp
add    $0x1,%r12d
cmp    0xc(%rsp),%r12d
jl     11a0 <main+0x80>
jmp    1162 <main+0x42>
xor    %eax,%eax
add    $0x18,%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
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
store i32 0, i32* %6
br label %10
10: ; preds = %43, %0
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %46
14: ; preds = %10
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
br label %46
19: ; preds = %14
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %5
br label %20
20: ; preds = %37, %19
%21 = load i32, i32* %5
%22 = load i32, i32* %2
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %24
%29 = load i32, i32* %5
%30 = load i32, i32* %7
%31 = sub nsw i32 %29, %30
%32 = load i32, i32* %8
%33 = add nsw i32 %32, %31
store i32 %33, i32* %8
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %36
36: ; preds = %28, %24
br label %37
37: ; preds = %36
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %20
40: ; preds = %20
%41 = load i32, i32* %8
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %40
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %10
46: ; preds = %18, %10
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 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %38
10: ; preds = %0, %32
%11 = phi i32 [ %35, %32 ], [ 0, %0 ]
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%13 = load i32, i32* %1
%14 = icmp eq i32 %13, 0
br i1 %14, label %38, label %15
15: ; preds = %10
%16 = icmp sgt i32 %13, 0
br i1 %16, label %17, label %32
17: ; preds = %15, %17
%18 = phi i32 [ %28, %17 ], [ 0, %15 ]
%19 = phi i32 [ %26, %17 ], [ 0, %15 ]
%20 = phi i32 [ %29, %17 ], [ 0, %15 ]
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%22 = load i32, i32* %2
%23 = icmp eq i32 %22, 0
%24 = sub nsw i32 %20, %19
%25 = zext i1 %23 to i32
%26 = add nuw nsw i32 %19, %25
%27 = select i1 %23, i32 %24, i32 0
%28 = add nsw i32 %27, %18
%29 = add nuw nsw i32 %20, 1
%30 = load i32, i32* %1
%31 = icmp slt i32 %29, %30
br i1 %31, label %17, label %32
32: ; preds = %17, %15
%33 = phi i32 [ 0, %15 ], [ %28, %17 ]
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = add nuw nsw i32 %11, 1
%36 = load i32, i32* %3
%37 = icmp slt i32 %35, %36
br i1 %37, label %10, label %38
38: ; preds = %32, %10, %0
ret i32 0
}