#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 *, long long *, ...);
int main(void) {
  long long int n, i, m, j, a, b, c, ans;
  scanf("%lld\n", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld\n", &m);
    ans = 0;
    for (j = 0; j < m; j++) {
      scanf("%lld %lld %lld", &a, &b, &c);
      ans += a * c;
    }
    printf("%lld\n", ans);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11e4 <main+0xc4>
lea    0xea2(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    11c3 <main+0xa3>
lea    0xe78(%rip),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x30(%rbp),%rax
imul   -0x40(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1179 <main+0x59>
mov    -0x48(%rbp),%rsi
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1149 <main+0x29>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xecb(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpq   $0x0,0x10(%rsp)
jle    11ee <main+0xce>
lea    0xeac(%rip),%r15
lea    0x28(%rsp),%r13
lea    0x30(%rsp),%r12
lea    0x20(%rsp),%rbp
xor    %ebx,%ebx
jmp    1195 <main+0x75>
nopw   0x0(%rax,%rax,1)
xor    %r14d,%r14d
lea    0xe86(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    0x18(%rsp),%rbx
add    $0x1,%rbx
cmp    0x10(%rsp),%rbx
jge    11ee <main+0xce>
mov    %r15,%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpq   $0x0,0x8(%rsp)
mov    %rbx,0x18(%rsp)
jle    1170 <main+0x50>
xor    %r14d,%r14d
xor    %r15d,%r15d
lea    0xe48(%rip),%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x20(%rsp),%rax
imul   0x28(%rsp),%rax
add    %rax,%r14
add    $0x1,%r15
cmp    0x8(%rsp),%r15
jl     11c0 <main+0xa0>
jmp    1173 <main+0x53>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%lld\0A\00"
@.str.1 = [15 x i8] c"%lld %lld %lld\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 ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %1)
%12 = load i64, i64* %1
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %36
14: ; preds = %0, %30
%15 = phi i64 [ %33, %30 ], [ 0, %0 ]
%16 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %2)
%17 = load i64, i64* %2
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %14, %19
%20 = phi i64 [ %26, %19 ], [ 0, %14 ]
%21 = phi i64 [ %27, %19 ], [ 0, %14 ]
%22 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i64* %3, i64* %4, i64* %5)
%23 = load i64, i64* %3
%24 = load i64, i64* %5
%25 = mul nsw i64 %24, %23
%26 = add nsw i64 %25, %20
%27 = add nuw nsw i64 %21, 1
%28 = load i64, i64* %2
%29 = icmp slt i64 %27, %28
br i1 %29, label %19, label %30
30: ; preds = %19, %14
%31 = phi i64 [ 0, %14 ], [ %26, %19 ]
%32 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %31)
%33 = add nuw nsw i64 %15, 1
%34 = load i64, i64* %1
%35 = icmp slt i64 %33, %34
br i1 %35, label %14, label %36
36: ; preds = %30, %0
ret i32 0
}