#include<iostream>
#include<cstdio>
#include<cmath>
typedef long long ll;
using namespace std;
int main()
{ int n,size,num,value,f;
ll sum;
cin>>n;
while(n--)
{ cin>>f;
sum=0;
for(int i=0;i<f;i++)
{
cin>>size>>num>>value;
sum+=size*value;
}
cout<<sum<<endl;
}
return 0;
}
11-02
11-02