#include using namespace std; const int MAX_N(26),INF(100); typedef long long ll; int n,ch[MAX_N*INF],num; #define rep(i,b,n) for(int i(b);i>T; while(T--) { cin>>n; int val,cnt; num=0; rep(i,0,n) { cin>>val>>cnt; rep(j,num,num+cnt)ch[j]=val; num+=cnt; } solve(); } return 0; } void solve() { sort(ch,ch+num); ll val,ans(0); rep(i,0,num) { val=0; rep(j,i,num)val+=ll(j-i+1)*ch[j]; ans=max(ans,val); if(ch[i]>=0)break; } cout<