#include #include #include #include using namespace std; struct node{ int x,y; }a[1000] ; bool cmp(node a,node b){ return a.x>b.x; } int main() { int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); for(int i=1;i<=n;i++){ int x,y; scanf("%d%d",&x,&y); a[i].x=x,a[i].y=y; } sort(a+1,a+1+n,cmp); int ans=0; int step=0; int sum=0; for(int i=1;i<=n;i++){ for(int j=1;j<=a[i].y;j++){ step=step+sum+a[i].x; sum+=a[i].x; // printf("--%d\n",step); if(step>=ans){ ans=step; } else break; } if(step