2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5
6 struct P{
7 int v;
8 int w;
9 }p[15];
10
11 int cmp(const void *a, const void *b){
12 struct P *c = (struct P *)a;
13 struct P *d = (struct P *)b;
14 return d->v - c->v;
15 }
16
17 int main(){
18 int n, s, m, a, b, i, ans;
19 scanf("%d", &n);
20 while(n--){
21 scanf("%d %d", &s, &m);
22 for(i = 0; i < s; i++){
23 scanf("%d %d", &p[i].v, &p[i].w);
24 }
25 qsort(p, s, sizeof(p[0]),cmp);
26 i = ans = 0;
27 while(m >= p[i].w){
28 ans += p[i].w * p[i].v;
29 m -= p[i].w;
30 i++;
31 }
32 ans += m * p[i].v;
33 printf("%d\n", ans);
34 }
35 return 0;
36 }
37