#include using namespace std; typedef long long ll; typedef pair pii; #define pb push_back #define all(a) a.begin(), a.end() #define sz(a) ((int)a.size()) #ifdef Doludu template ostream& operator << (ostream &o, vector vec) { o << "{"; int f = 0; for (T i : vec) o << (f++ ? " " : "") << i; return o << "}"; } void bug__(int c, auto ...a) { cerr << "\e[1;" << c << "m"; (..., (cerr << a << " ")); cerr << "\e[0m" << endl; } #define bug_(c, x...) bug__(c, __LINE__, "[" + string(#x) + "]", x) #define bug(x...) bug_(32, x) #define bugv(x...) bug_(36, vector(x)) #define safe bug_(33, "safe") #else #define bug(x...) void(0) #define bugv(x...) void(0) #define safe void(0) #endif const int mod = 998244353, N = 1 << 20; void solve() { int n, m, k; ll p; cin >> n >> m >> k >> p; auto read = [&](int cnt) { vector > a(cnt); for (int i = 0; i < cnt; ++i) cin >> a[i].first, a[i].second = i; vector >> pos(k); for (int i = 0, x; i < cnt; ++i) cin >> x, pos[--x].pb(a[i]); sort(all(a)); for (int i = 0; i < k; ++i) sort(all(pos[i])); return pair(a, pos); }; auto [aa, a] = read(n); auto [bb, b] = read(m); vector s(k); for (int i = 0; i < k; ++i) cin >> s[i]; auto get = [&](vector > &vec, ll x) { return lower_bound(all(vec), pair(x + 1, -1)) - vec.begin(); }; auto query = [&](ll x) { ll ans = 0; for (int i = 0; i < k; ++i) { for (auto [cur, id] : a[i]) { ans += get(bb, x - cur) - get(b[i], x - cur) + get(b[i], x + s[i] - cur); } } return ans; }; ll l = 0, r = 1ll << 32; while (r - l > 1) { ll mid = l + r >> 1; if (query(mid) < p) l = mid; else r = mid; } ll res = r; map mp; for (int i = 0; i < k; ++i) { for (auto [x, id] : b[i]) { mp[{x, i}] = id; } } pii ans(-1, -1); for (int i = 0; i < k; ++i) for (auto [x, id] : a[i]) { auto it = mp.lower_bound({res - x, -1}); while (true) { if (it == mp.end() || (it->first).first != res - x) break; if ((it->first).second == i) { it = next(it); } else { ans = {id, it->second}; break; } } if (mp.count({res + s[i] - x, i})) { ans = {id, mp[{res + s[i] - x, i}]}; } } bug(res); cout << ans.first + 1 << " " << ans.second + 1 << "\n"; } int main() { ios::sync_with_stdio(false), cin.tie(0); int t; cin >> t; while (t--) { solve(); } }