/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int t;
int n;
LL ans, a, b;

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	scanf("%d", &t);
	while(t--){
		scanf("%d", &n);
		ans = 0;
		for (int i = 1; i <= n; i++){
			scanf("%lld %lld", &a, &b);
			ans += a * b;
		}
		printf("%lld\n", ans);
	}

	return 0;
}
/**/