#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rs id * 2 + 1
#define ls id * 2
#define pii pair<int, int>
const int N = 1e6 + 10;
int T, L, V, n, m;
int d[N], v[N], a[N], p[N], ans1, ans2, vis[N], cnt[N], dis[N];
pii pass[N];
vector<pii> ok;
vector<pii> G[N];
queue<int> q;
void spfa(){
memset(vis, 0, sizeof vis);
memset(cnt, 0, sizeof cnt);
for(int i = 0; i <= L; i++) dis[i] = 1e9;
dis[0] = 0;
while(q.size()) q.pop();
q.push(0);
vis[0] = 1;
cnt[0] = 1;
while(q.size()){
int ww = q.front();
q.pop();
vis[ww] = 0;
for(auto v : G[ww]){
int to = v.first, len = v.second;
if(dis[ww] + len < dis[to]){
dis[to] = dis[ww] + len;
if(vis[to] == 0){
vis[to] = 1;
q.push(to);
}
}
}
}
}
signed main(){
freopen("detect.in", "r", stdin);
freopen("detect.out", "w", stdout);
scanf("%lld", &T);
while(T--){
ans1 = 0, ans2 = 0;
scanf("%lld %lld %lld %lld", &n, &m, &L, &V);
L++;
for(int i = 1; i <= m; i++) vis[i] = 0;
for(int i = 1; i <= n; i++){
scanf("%lld %lld %lld", &d[i], &v[i], &a[i]);
d[i]++;
}
for(int i = 1; i <= m; i++){
scanf("%lld", &p[i]);
p[i]++;
}
for(int i = 0; i <= L; i++) G[i].clear();
sort(p + 1, p + 1 + m);
p[m + 1] = 1e9;
for(int i = 1; i <= n; i++){
if(a[i] > 0){
int dis = V * V - v[i] * v[i];
int pas = ((2 * a[i]) + dis - 1) / (2 * a[i]);
int x = pas + d[i];
int o = upper_bound(p + 1, p + 1 + (m + 1), x) - p;
if(o <= m){
pass[i] = {o, m};
}else{
pass[i] = {-1, -1};
}
}else if(a[i] < 0){
int dis = V * V - v[i] * v[i];
int pas = (dis + 2 * a[i] + 1) / (2 * a[i]);
int x = pas + d[i];
int o = upper_bound(p + 1, p + 1 + (m + 1), x) - p;
o--;
int ro = upper_bound(p + 1, p + 1 + (m + 1), d[i]) - p;
if(ro <= o){
pass[i] = {ro, o};
}else{
pass[i] = {-1, -1};
}
}else if(a[i] == 0){
if(v[i] > V){
int l = lower_bound(p + 1, p + 1 + m, d[i]) - p;
if(l <= m){
pass[i] = {l, m};
}else{
pass[i] = {-1, -1};
}
}else{
pass[i] = {-1, -1};
}
}
}
ok.clear();
for(int i = 1; i <= n; i++){
if(pass[i].first == -1 && pass[i].second == -1) ans1++;
else ok.push_back(pass[i]);
}
ans1 = n - ans1;
for(auto v : ok){
G[v.first - 1].push_back({v.second, -1});
}
for(int i = 1; i <= L; i++){
G[i].push_back({i - 1, 1});
G[i - 1].push_back({i, 0});
}
spfa();
ans2 = m + dis[L];
printf("%lld %lld\n", ans1, ans2);
}
}