#include #include #include #include using namespace std; struct rec{ int x; bool operator <(const rec &another)const{ return x>another.x; } }ha; priority_queue a,b; int now,n,m,p[100009],belong[100009],c[100009],T; int main(){ #ifdef YJQ_LOCAL freopen(".in","r",stdin); freopen(".out","w",stdout); #endif scanf("%d",&T); while(T--){ now=0; scanf("%d%d",&n,&m); while(!a.empty()) a.pop(); while(!b.empty()) b.pop(); memset(p,0,sizeof(p)); for (int i=1;i<=n;i++){ scanf("%d%d",&belong[i],&c[i]); } for (int i=1;i<=m;i++){ scanf("%d",&p[i]); } p[m+1]=0x3f3f3f3f; sort(p+1,p+1+m); for (int i=1;i<=n;i++){ ha.x=c[i]-now; if (belong[i]==0){ while(!b.empty() && b.top().x