#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#include <time.h>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// to erase in multiset-> less_equal<T> and
// s.erase(s.find_by_order(s.order_of_key(x)))
// lower_bound(x)=>(cannot use the stl lower_bound function)
// ll idx = s.order_of_key(x)
// if(idx == s.size()) -> no lower_bound
// else lb = *s.find_by_order(idx) // as 0-indexing
// idx-1 will give highest value which is strictly less than x
// for upper_bound->do the same with (x+1)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef tuple<ll, ll, ll> t64;
typedef vector<t64> vt64;
typedef vector<vt64> vvt64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef vector<vector<p32> > vvp32;
typedef vector<bool> vb;
ll mod = 1e9+7, MOD = 998244353;
double eps = 1e-12;
#define FOR(s, e, i) for(ll i = s; i <= e; i++)
#define ROF(s ,e, i) for(ll i = s; i >= e; i--)
#define F0R(i, e) for(ll i = 0; i < (e); i++)
#define trav(e, a) for(auto &e : a)
#define coutAll(A) for(auto asdafas : A) cout << asdafas << " "; cout << "\n";
#define foutAll(A) for(auto asdafas : A) fout << asdafas << " "; cout << "\n";
#define cinAll(A) for(auto &asdafas : A) cin >> asdafas;
#define finAll(A) for(auto &asdafas : A) fin >> asdafas;
#define minpq priority_queue<ll, v64, greater<ll>>
#define maxpq priority_queue<ll>
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
ll inf = LLONG_MAX;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
#define MAXN 100000000
void solve(int it)
{
ll n, m, k, w;
cin >> n >> m >> k >> w;
vector<pair<ll, bool>>A;
FOR(0, n - 1, i){
ll x;
cin >> x;
A.emplace_back(x, true);
}
FOR(0, m - 1, i){
ll x;
cin >> x;
A.emplace_back(x, false);
}
// setting left and right boundary with black
A.emplace_back(0, false);
A.emplace_back(w+1, false);
sort(all(A));
vp64 B;
vv64 way;
auto f = [&]()->ll{
// trav(e, B){
// cout << e.fi << "(" << e.se << ") ";
// }
// cout << "\n";
if(sz(B)<2) return 0;
if(!(!B[0].se and !B.back().se)) return 0;
if(sz(B) == 2) return 0;
// trav(e, B){
// cout << e.fi << "(" << e.se << ") ";
// }
// cout << "\n";
ll cnt = 0;
ll last = -1;
v64 temp;
FOR(1, sz(B)-1, i){
if(!B[i].se){
break;
}
if(last == -1){
last = B[i].fi;
temp.pb(last);
++cnt;
continue;
}
if(B[i].fi <= last+k-1){
continue;
}
++cnt;
last = B[i].fi;
temp.pb(last);
}
// cout << cnt << "\n";
if(k*cnt > B.back().fi-B[0].fi-1) return -1;
ll pichao = B[sz(B)-2].fi+k - B.back().fi;
// cout << pichao << "\n";
// coutAll(temp);
if(pichao > 0){
temp.back() -= pichao;
ROF(sz(B)-3, 1, i){
temp[i] = min(temp[i]-pichao, temp[i+1]);
}
}
way.pb(temp);
// trav(e, temp) way.pb(e);
// way.insert(way.end(), all(temp));
// coutAll(temp);
// coutAll(way);
// cout << cnt << " done\n";
ll res = cnt;
return res;
};
ll ans = 0;
trav(e, A){
// cout << e.fi << "=>\n";
B.pb(e);
if(e.se) continue;
// cout << "start\n";
ll res = f();
// cout << "done\n";
B.clear();
B.pb(e);
if(res == -1){
cout << -1 << "\n";
return;
}
// cout << "done\n";
ans += res;
}
cout << ans << "\n";
// coutAll(way);
trav(v, way){
trav(e, v) cout << e<< " ";
}
cout << '\n';
}
int main()
{
fast_cin();
ll t = 1;
cin >> t;
for(int it=1; it<=t; it++)
{
//cout << "Case " << it << ": ";
solve(it);
}
return 0;
}