#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>usingnamespacestd;
constint maxn = 50005;
int sum[maxn];
int b[maxn];
int a[maxn];
int main(){
int T;
cin>>T;
int n,m;
while (T--){
cin>>n>>m;
for (int i=1;i<=n;i++){
scanf("%d%d",&a[i],&b[i]);
}
memset(sum,0,sizeof(sum));
for (int i=0;i<m;i++){
int tmp;
scanf("%d",&tmp);
sum[tmp]++;
}
int v[2] = {0,0};
int ans = 0;
int tot = 0;
for (int i=n;i>0;i--){
tot += sum[i];
int j = (a[i] ^ 1);
if (b[i] + tot >= v[j]){
ans++;
}
v[a[i]] = max(v[a[i]],b[i] + tot);
}
cout << ans <<"\n";
}
return0;
}