#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 long);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int n, f;
  int space, degree, animals;
  long long premium;
  scanf("%d\n", &n);
  while (n-- > 0) {
    scanf("%d\n", &f);
    premium = 0;
    while (f-- > 0) {
      scanf("%d %d %d\n", &space, &animals, &degree);
      premium += (long long)space * (long long)degree;
    }
    printf("%lld\n", premium);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed0(%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
jle    11cb <main+0xab>
lea    0xeaa(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    11b6 <main+0x96>
lea    0xe76(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
movslq -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   %rcx,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    116f <main+0x4f>
mov    -0x20(%rbp),%rsi
lea    0xe49(%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   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xed1(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
test   %eax,%eax
jle    11f5 <main+0xd5>
lea    0xea5(%rip),%r12
lea    0x10(%rsp),%r13
lea    0x14(%rsp),%rbx
lea    0xc(%rsp),%rbp
lea    0xe99(%rip),%r14
jmp    119a <main+0x7a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
test   %eax,%eax
jle    11f5 <main+0xd5>
lea    0xe65(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x4(%rsp)
xor    %r15d,%r15d
test   %eax,%eax
jle    1180 <main+0x60>
nop
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
movslq 0x10(%rsp),%rax
movslq 0xc(%rsp),%rcx
imul   %rax,%rcx
add    %rcx,%r15
mov    0x4(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x4(%rsp)
test   %eax,%eax
jg     11c0 <main+0xa0>
jmp    1180 <main+0x60>
xor    %eax,%eax
add    $0x18,%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 = [10 x i8] c"%d %d %d\0A\00"
@.str.2 = [6 x i8] c"%lld\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 i64
store i32 0, i32* %1
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %28, %0
%10 = load i32, i32* %2
%11 = add nsw i32 %10, -1
store i32 %11, i32* %2
%12 = icmp sgt i32 %10, 0
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
store i64 0, i64* %7
br label %15
15: ; preds = %19, %13
%16 = load i32, i32* %3
%17 = add nsw i32 %16, -1
store i32 %17, i32* %3
%18 = icmp sgt i32 %16, 0
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %6, i32* %5)
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = mul nsw i64 %22, %24
%26 = load i64, i64* %7
%27 = add nsw i64 %26, %25
store i64 %27, i64* %7
br label %15
28: ; preds = %15
%29 = load i64, i64* %7
%30 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %29)
br label %9
31: ; preds = %9
ret i32 0
}

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