#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 *, long *, ...);
int main() {
  long int a, b, c, d, n, t;
  scanf("%ld", &t);
  while (t--) {
    scanf("%ld", &n);
    d = 0;
    while (n--) {
      scanf("%ld %ld %ld", &a, &b, &c);
      d += a * c;
    }
    printf("%ld\n", d);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed2(%rip),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
cmp    $0x0,%rax
je     11d2 <main+0xb2>
lea    0xea7(%rip),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x30(%rbp)
cmp    $0x0,%rax
je     11bd <main+0x9d>
lea    0xe6c(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rax
imul   -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1174 <main+0x54>
mov    -0x28(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xed3(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subq   $0x1,(%rsp)
jae    1157 <main+0x37>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xeae(%rip),%r12
lea    0xe9b(%rip),%r13
lea    0x18(%rsp),%rbx
lea    0x20(%rsp),%rbp
lea    0x10(%rsp),%r14
jmp    1195 <main+0x75>
cs nopw 0x0(%rax,%rax,1)
xor    %r15d,%r15d
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
subq   $0x1,(%rsp)
jb     1146 <main+0x26>
lea    0xe6c(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subq   $0x1,0x8(%rsp)
jb     1180 <main+0x60>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%rax
imul   0x18(%rsp),%rax
add    %rax,%r15
subq   $0x1,0x8(%rsp)
jae    11c0 <main+0xa0>
jmp    1183 <main+0x63>

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
@.str.1 = [12 x i8] c"%ld %ld %ld\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %7)
br label %9
9: ; preds = %26, %0
%10 = load i64, i64* %7
%11 = add nsw i64 %10, -1
store i64 %11, i64* %7
%12 = icmp ne i64 %10, 0
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %6)
store i64 0, i64* %5
br label %15
15: ; preds = %19, %13
%16 = load i64, i64* %6
%17 = add nsw i64 %16, -1
store i64 %17, i64* %6
%18 = icmp ne i64 %16, 0
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64* %2, i64* %3, i64* %4)
%21 = load i64, i64* %2
%22 = load i64, i64* %4
%23 = mul nsw i64 %21, %22
%24 = load i64, i64* %5
%25 = add nsw i64 %24, %23
store i64 %25, i64* %5
br label %15
26: ; preds = %15
%27 = load i64, i64* %5
%28 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %27)
br label %9
29: ; preds = %9
ret i32 0
}

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