#include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef unsigned long long ULL; int T, n; struct Point{ int val, cnt; }a[55]; bool cmp(Point x, Point y) { return x.val > y.val; } int main() { scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d%d", &a[i].val, &a[i].cnt); sort(a + 1, a + n + 1, cmp); int ans = 0, res = 0, sum = 0; int pos = 1; while(pos <= n) { while(a[pos].cnt != 0) { res += sum; sum += a[pos].val; res += a[pos].val; ans = max(res, ans); a[pos].cnt--; } if(a[pos].cnt == 0) pos++; } printf("%d\n", ans); } }