#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// 检查是否能覆盖所有红色单元格
bool check(vector<int>& red, vector<int>& black, int k, int w) {
int n = red.size();
int m = black.size();
int i = 0, j = 0;
int cnt = 0;
while (i < n) {
int left = red[i];
int right = left + k - 1;
// 检查是否覆盖黑色单元格
bool flag = true;
while (j < m && black[j]<right) {
if (black[j] >= left) {
flag = false;
break;
}
j++;
}
if (flag) {
cnt++;
i = upper_bound(red.begin(), red.end(), right)-red.begin();
} else {
return false;
}
}
return true;
}
int main() {
int T;
cin >> T;
while (T--) {
int n, m, k, w;
cin >> n >> m >> k >> w;
vector<int> red(n);
for (int i = 0; i < n; i++) {
cin >> red[i];
}
sort(red.begin(), red.end());
vector<int> black(m);
for (int i = 0; i < m; i++) {
cin >> black[i];
}
sort(black.begin(), black[i]);
if (check(red, black, k, w)) {
int i = 0;
int cnt = 0;
int left = red[0];
cnt++;
for (int j = 1; j < n; j++) {
if (red[j]>left + k - 1) {
left = red[j];
cnt++;
}
}
cout << cnt << endl;
} else {
cout << -1 << endl;
}
}
return 0;
}