#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 *, long);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int n, f;
  long int size, animal, friendship;
  long int soma[20];
  int i = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &f);
    soma[i] = 0;
    while (f > 0) {
      scanf("%ld", &size);
      scanf("%ld", &animal);
      scanf("%ld", &friendship);
      soma[i] += size * friendship;
      f--;
    }
  }
  for (i = 0; i < n; i++) {
    printf("%ld\n", soma[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xd4(%rbp)
lea    0xebd(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0xd4(%rbp)
mov    -0xd4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1213 <main+0xf3>
lea    0xe92(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movslq -0xd4(%rbp),%rax
movq   $0x0,-0xd0(%rbp,%rax,8)
cmpl   $0x0,-0xc(%rbp)
jle    11fa <main+0xda>
lea    0xe66(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xe54(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xe42(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x18(%rbp),%rcx
imul   -0x28(%rbp),%rcx
movslq -0xd4(%rbp),%rax
add    -0xd0(%rbp,%rax,8),%rcx
ff
mov    %rcx,-0xd0(%rbp,%rax,8)
ff
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    118c <main+0x6c>
jmp    11ff <main+0xdf>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    1158 <main+0x38>
movl   $0x0,-0xd4(%rbp)
mov    -0xd4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    125b <main+0x13b>
movslq -0xd4(%rbp),%rax
mov    -0xd0(%rbp,%rax,8),%rsi
ff
lea    0xdc5(%rip),%rdi
call   1030 <printf@plt>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    121d <main+0xfd>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
lea    0xec8(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    122b <main+0x10b>
lea    0xead(%rip),%rbx
lea    0x10(%rsp),%r12
lea    0x18(%rsp),%r13
lea    0x8(%rsp),%rbp
xor    %r14d,%r14d
jmp    117e <main+0x5e>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
movslq 0x4(%rsp),%rax
cmp    %rax,%r14
jge    11fd <main+0xdd>
lea    0xe7b(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movq   $0x0,0x20(%rsp,%r14,8)
cmpl   $0x0,(%rsp)
jle    1170 <main+0x50>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%rax
imul   0x10(%rsp),%rax
add    %rax,%r15
mov    %r15,0x20(%rsp,%r14,8)
mov    (%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,(%rsp)
cmp    $0x1,%eax
jg     11b0 <main+0x90>
jmp    1170 <main+0x50>
test   %eax,%eax
jle    122b <main+0x10b>
xor    %ebp,%ebp
lea    0xdfd(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    0x20(%rsp,%rbp,8),%rsi
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
cmp    %rax,%rbp
jl     1210 <main+0xf0>
xor    %eax,%eax
add    $0xc8,%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"%ld\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca [20 x i64]
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %8
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %8
br label %10
10: ; preds = %37, %0
%11 = load i32, i32* %8
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %40
14: ; preds = %10
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [20 x i64], [20 x i64]* %7, i64 0, i64 %17
store i64 0, i64* %18
br label %19
19: ; preds = %22, %14
%20 = load i32, i32* %3
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %19
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %4)
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %5)
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %6)
%26 = load i64, i64* %4
%27 = load i64, i64* %6
%28 = mul nsw i64 %26, %27
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20 x i64], [20 x i64]* %7, i64 0, i64 %30
%32 = load i64, i64* %31
%33 = add nsw i64 %32, %28
store i64 %33, i64* %31
%34 = load i32, i32* %3
%35 = add nsw i32 %34, -1
store i32 %35, i32* %3
br label %19
36: ; preds = %19
br label %37
37: ; preds = %36
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %10
40: ; preds = %10
store i32 0, i32* %8
br label %41
41: ; preds = %51, %40
%42 = load i32, i32* %8
%43 = load i32, i32* %2
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %54
45: ; preds = %41
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [20 x i64], [20 x i64]* %7, i64 0, i64 %47
%49 = load i64, i64* %48
%50 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %49)
br label %51
51: ; preds = %45
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %41
54: ; preds = %41
ret i32 0
}

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