#include #include #include #include #include using namespace std; int main() { int t; scanf("%d",&t); vector a; while(t--){ a.clear(); int n; scanf("%d",&n); while(n--){ int val,cnt; scanf("%d%d",&val,&cnt); while(cnt--){ a.push_back(val); } } sort(a.begin(),a.end(),greater()); int ans=0; int temp=0; int cur=0; for(int i=0;i