我是来存RMQ板的
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <ctime>
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
#define INF 1e9
#define maxn 110010
#define maxm 100086+10
#define mod 1000000009
#define eps 1e-7
#define PI acos(-1.0)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(n) scanf("%d",&n)
#define scanll(n) scanf("%I64d",&n)
#define scan2(n,m) scanf("%d%d",&n,&m)
#define scanll2(n,m) scanf("%I64d%I64d",&n,&m)
#define scans(s) scanf("%s",s);
#define ini(a) memset(a,0,sizeof(a))
#define out(n) printf("%d\n",n)
#define outll(n) printf("%I64d\n",n)
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int n,m;
int s[maxn];
int p[maxn];
ll a[maxn];
ll d[maxn][31];
void RMQ_init()
{
rep(i,n) d[i][0] = a[i];
for(int j=1;(1<<j) <= n; j++)
for(int i = 0;i+(1<<j)-1 < n; i++)
d[i][j] = min(d[i][j-1], d[i+(1<<(j-1))][j-1]);
}
ll query(int L,int R)
{
int k = 0;
while((1<<(k+1)) <= R-L+1) k++;
return min(d[L][k], d[R-(1<<k)+1][k]);
}
ll solve(int x)
{
int pos = lower_bound(s,s+n,x) - s;
if(pos >= n) return (ll)x * p[n-1];
ll ans = 0;
if(s[pos] == x) ans = a[pos];
else ans = (ll)x * p[pos-1];
ans = min(ans,query(pos,n-1));
return ans;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
int T;
cin>>T;
while(T--)
{
scanf("%d%d",&n,&m);
rep(i,n)
{
scanf("%d%d",&s[i],&p[i]);
a[i] = (ll)s[i] * p[i];
}
RMQ_init();
int x;
while(m--)
{
scan(x);
printf("%I64d\n",solve(x));
}
}
return 0;
}