#include<stdio.h>
struct good{
int price;
int weight;
}a[11],temp;
int main()
{ int n;
int i,j;int s,m;
scanf("%d",&n);
while(n--)
{ int sum1=0,sum2=0;
scanf("%d %d",&s,&m);
for(i=0;i<s;i++)
scanf("%d %d",&a[i].price,&a[i].weight);
for(i=0;i<s;i++)
for(j=i+1;j<s;j++)
if(a[i].price<a[j].price)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
for(i=0;i<s;i++)
{
sum1+=a[i].weight;
sum2+=a[i].weight*a[i].price;
if(sum1>=m)
break;
}
int w=sum1-m;
if(w>=0)
sum2-=w*a[i].price;
printf("%d\n",sum2);
}
return 0;
}