#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 *, ...);
int main() {
  int test_case_num;
  int num_farmer;
  int size_farmeyard;
  int environment_friendliness;
  long budget;
  scanf("%d", &test_case_num);
  while (test_case_num--) {
    scanf("%d", &num_farmer);
    budget = 0;
    while (num_farmer--) {
      scanf("%d%*d%d", &size_farmeyard, &environment_friendliness);
      budget += (long)size_farmeyard * environment_friendliness;
    }
    printf("%ld\n", budget);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xecf(%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
je     11c7 <main+0xa7>
lea    0xea9(%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
je     11b2 <main+0x92>
lea    0xe76(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
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    0xe4b(%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    0xed0(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    1159 <main+0x39>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8(%rsp),%r15
lea    0xea3(%rip),%r12
lea    0xe94(%rip),%r13
lea    0x14(%rsp),%rbx
lea    0x10(%rsp),%rbp
jmp    1195 <main+0x75>
nopl   0x0(%rax,%rax,1)
xor    %r14d,%r14d
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
subl   $0x1,0xc(%rsp)
jb     1148 <main+0x28>
lea    0xe69(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0x8(%rsp)
jb     1180 <main+0x60>
xor    %r14d,%r14d
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
movslq 0x14(%rsp),%rax
movslq 0x10(%rsp),%rcx
imul   %rax,%rcx
add    %rcx,%r14
subl   $0x1,0x8(%rsp)
jae    11b0 <main+0x90>
jmp    1183 <main+0x63>

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

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