#include<stdio.h>
#include<stdlib.h>
struct Node
{
double value;
double weight;
}a[10];
void quick_sort(struct Node *arr, int l, int r)
{
if (l < r)
{
int i = l, j = r, x = arr[l].value;
struct Node temp = arr[l];
while (i < j)
{
while (i < j && x <= arr[j].value)
j--;
if (i < j)
arr[i++] = arr[j];
while (i < j && x > arr[i].value)
i++;
if (i < j)
arr[j--]= arr[i];
}
arr[i] = temp;
quick_sort(arr, l ,i - 1);
quick_sort(arr, i + 1, r);
}
}
int main()
{
int s, i, j;
scanf("%d",&s);
while (s--)
{
int n;
double m, total_value = 0, total_weight = 0;
scanf("%d%lf",&n, &m);
for (i = 0; i < n; i++)
scanf("%lf%lf",&a[i].value, &a[i].weight);
quick_sort(a, 0, n - 1);
for (i = n - 1; i >= 0; i--)
{
if (total_weight + a[i].weight <= m)
{
total_weight += a[i].weight;
total_value += a[i].value * a[i].weight;
}
else
break;
}
total_value += (m - total_weight) * a[i].value;
printf("%d\n",(int)total_value);
}
return 0;
}