#include<bits/stdc++.h>
#define int long long
#define maxn 100010
using namespace std;
int t,n,m,L,V,p[maxn],ans;
struct node{
int d,v,a;
int flg;
int lu,ld,lb,ru,rd,rb;
}c[maxn];
inline int read(){
int ret=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')ret=ret*10+(ch&15),ch=getchar();
return ret*f;
}
bool checkA(){
for(int i=1;i<=n;i++)if(c[i].a!=0)return 0;
int r=0;
for(int i=1;i<=m;i++)r=max(r,p[i]);
int ans=0;
for(int i=1;i<=n;i++){
if(c[i].d>r)continue;
if(c[i].v>V){
ans++;
}
}
if(ans==0)printf("0 %lld\n",m);
else printf("%lld %lld\n",ans,m-1);
return 1;
}
int comp(int u,int d,int x){
if(u-d*x>0)return 1;
if(u-d*x==0)return 0;
if(u-d*x<0)return -1;
}
signed main(){
freopen("detect.in","r",stdin);
freopen("detect.out","w",stdout);
t=read();
while(t--){
memset(c,0,sizeof(c));
n=read(),m=read(),L=read(),V=read(),ans=0;
for(int i=1;i<=n;i++)c[i].d=read(),c[i].v=read(),c[i].a=read();
for(int i=1;i<=m;i++)p[i]=read();
if(checkA()){
continue;
}
for(int i=1;i<=n;i++){
if(c[i].v<V){
if(c[i].a>0){
c[i].lb=0,c[i].rb=1;
int uu=(V-c[i].v)*(V+c[i].v),dd=c[i].a*2;
c[i].lu=uu,c[i].ld=dd;
if(dd<0)c[i].lu=-uu,c[i].ld=-dd;
c[i].ru=L,c[i].rd=1;
}
if(c[i].a==0)c[i].flg=1;
if(c[i].a<0)c[i].flg=1;
}
if(c[i].v==V){
if(c[i].a>0){
c[i].lb=0,c[i].rb=1;
c[i].lu=c[i].d,c[i].ld=1;
c[i].ru=L,c[i].rd=1;
}
if(c[i].a==0)c[i].flg=1;
if(c[i].a<0)c[i].flg=1;
}
if(c[i].v>V){
if(c[i].a>0){
c[i].lb=1,c[i].rb=1;
c[i].lu=c[i].d,c[i].ld=1;
c[i].ru=L,c[i].rd=1;
}
if(c[i].a==0){
c[i].lb=1,c[i].rb=1;
c[i].lu=c[i].d,c[i].ld=1;
c[i].ru=L,c[i].rd=1;
}
if(c[i].a<0){
c[i].lb=1,c[i].rb=0;
int uu=(V-c[i].v)*(V+c[i].v),dd=c[i].a*2;
c[i].lu=c[i].d,c[i].ld=1;
c[i].ru=uu,c[i].rd=dd;
if(dd<0)c[i].lu=-uu,c[i].ld=-dd;
}
}
}
for(int i=1;i<=n;i++){
if(c[i].flg)continue;
int ff=1;
for(int j=1;j<=m&&ff;j++){
int ok=0;
if(comp(c[i].lu,c[i].ld,p[j])==-1)ok++;
if(comp(c[i].ru,c[i].rd,p[j])==1)ok++;
if(c[i].lb&&comp(c[i].lu,c[i].ld,p[j])==0)ok++;
if(c[i].rb&&comp(c[i].ru,c[i].rd,p[j])==0)ok++;
if(ok==2){
ff=0;
ans++;
}
}
}
printf("%lld\n",ans);
continue;
}
return 0;
}