#include <stdio.h>
int main ()
{
long long int ls, al ,fn, sum ,p ;
int n ,i , j , f ;
scanf ("%d",&n) ;
{
for (j=1 ; j<= n ; j++)
{
scanf ("%d",&f) ;
sum =0 ;
for (i=1 ; i<= f ; i++)
{
scanf ("%lld %lld %lld",& ls,& al,& fn ) ;
p = ls * fn ;
sum = sum + p ;
}
printf ("%lld\n",sum) ;
}
}
return 0 ;
}
int main ()
{
long long int ls, al ,fn, sum ,p ;
int n ,i , j , f ;
scanf ("%d",&n) ;
{
for (j=1 ; j<= n ; j++)
{
scanf ("%d",&f) ;
sum =0 ;
for (i=1 ; i<= f ; i++)
{
scanf ("%lld %lld %lld",& ls,& al,& fn ) ;
p = ls * fn ;
sum = sum + p ;
}
printf ("%lld\n",sum) ;
}
}
return 0 ;
}