1. 

import java.io.*;
import java.util.*;

class Main {

public static void main(String...args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input;
String s[];
long sum;
int farmers, caseNumbers = Integer.parseInt(reader.readLine());

for(int c=0; c < caseNumbers; c++)
{
farmers = Integer.parseInt(reader.readLine());
sum = 0;

for(int f = 0; f < farmers; f++)
{
s = reader.readLine().split(" ");
sum += Integer.parseInt(s[0])*Integer.parseInt(s[2]);
}
System.out.println(sum);
}
}
}