#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<int,int> Good;
bool cmp(const Good& a,const Good& b){
return a.first > b.first;
}
int main(){
int n;
cin >>n;
for(int icase = 0 ; icase <n ; ++icase){
int s,m;
cin >>s >>m;
vector<Good> goods(s);
for(int i = 0 ; i < s; ++ i)
cin >> goods[i].first>>goods[i].second;
sort(goods.begin(),goods.end(),cmp);
int res = 0;
for(int i = 0 ; i < s && m> 0; ++ i){
if(m > goods[i].second){
m-=goods[i].second;
res+=goods[i].first*goods[i].second;
}else{
res+=goods[i].first*m;
break;
}
}
cout<<res<<endl;
}
}