#include <bits/stdc++.h>
using namespace std;
#define For(i,j,k) for(int i=j;i<=k;i++)
int d[100005],v[100005],a[100005],f[100005],t[100005];
int T,n,m,L,V;
int p[100005];
int c[100005];
int ab[100005];
int ans1=0,ans2=INT_MAX,cnt=0;;
int qiuS(int v0,int a)
{
int x=(V+v0)*(V-v0);
if((V+v0)*(V-v0)%(2*a)==0)return (V+v0)*(V-v0)/2/a;
else return (V+v0)*(V-v0)/(2*a)+1;
}
int qiuS2(int v0,int a)
{
return (V+v0)*(V-v0)/(2*a);
}
bool full()
{
int cn=0;
For(i,1,n)
{
if(ab[i]==1)cn++;
}
if(cn==ans1)return true;
return false;
}
void dg(int x)
{
if(x>m)
{
if(full())
{
ans2=min(ans2,cnt);
}
return;
}
dg(x+1);
queue<int> q;
For(i,1,n)
{
if(f[i]<=p[x]&&p[x]<=t[i]&&ab[x]==0)
{
ab[x]=1;
q.push(x);
}
}
cnt++;
dg(x+1);
cnt--;
while(!q.empty())
{
ab[q.front()]=0;
q.pop();
}
}
int main()
{
freopen("detect.in","r",stdin);
freopen("detect.out","w",stdout);
cin>>T;
while(T--)
{
memset(c,0,sizeof(c));
ans1=0;
cin>>n>>m>>L>>V;
For(i,1,n)
cin>>d[i]>>v[i]>>a[i];
For(i,1,m)
cin>>p[i];
For(i,1,n)
{
int from,to;
if(v[i]>V&&a[i]>=0)
{
from=d[i];
to=p[m];
}
else if(v[i]<=V&&a[i]<=0)
{
from=-1;
to=-1;
}
else if(v[i]<=V&&a[i]>0)
{
from=qiuS(v[i],a[i])+d[i];
to=p[m];
}
else if(v[i]>V&&a[i]<0)
{
from=d[i];
to=qiuS2(v[i],a[i])+d[i];
}
if(from!=-1)
{
int e=lower_bound(p+1,p+m+1,from)-p;
int f=upper_bound(p+1,p+m+1,to)-p-1;
if(e<=m&&p[e]<=to)
{
ans1++;
}
}
f[i]=from,t[i]=to;
}
memset(ab,0,sizeof(ab));
dg(1);
cout<<ans1<<" "<<ans2<<endl;
}
return 0;
}