from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right from itertools import permutations, combinations from heapq import heappop, heappush import math, sys input = lambda: sys.stdin.readline().rstrip("\r\n") _int = lambda x: int(x)-1 MOD = 998244353 #10**9+7 INF = 1<<60 Yes, No = "Yes", "No" class FenwickTree: '''Reference: https://en.wikipedia.org/wiki/Fenwick_tree''' def __init__(self, n: int = 0) -> None: self._n = n self.data = [0] * n def add(self, p: int, x) -> None: assert 0 <= p < self._n p += 1 while p <= self._n: self.data[p - 1] += x p += p & -p def sum(self, left: int, right: int): assert 0 <= left <= right <= self._n return self._sum(right) - self._sum(left) def _sum(self, r: int): s = 0 while r > 0: s += self.data[r - 1] r -= r & -r return s for _ in range(int(input())): N, M, K, P = map(int, input().split()) T = list(map(int, input().split())) C = list(map(int, input().split())) B = list(map(int, input().split())) D = list(map(int, input().split())) S = list(map(int, input().split())) Y = set() KA = [[] for _ in range(K)] for i in range(N): KA[C[i]-1].append(T[i]) Y.add(T[i]) Y.add(T[i]-S[C[i]-1]) KB = [[] for _ in range(K)] for i in range(M): KB[D[i]-1].append(B[i]) Y.add(B[i]) X = sorted(list(Y)) pos = {x: e for e, x in enumerate(X)} L = len(X) def check(m): F = FenwickTree(L) for i in range(N): F.add(pos[T[i]], 1) ret = 0 for i in range(K): for a in KA[i]: F.add(pos[a], -1) F.add(pos[a-S[i]], 1) for b in KB[i]: j = bisect_right(X, m-b) ret += F.sum(0, j) for a in KA[i]: F.add(pos[a-S[i]], -1) F.add(pos[a], 1) return ret < P def calc(m): F1 = FenwickTree(L) for i in range(N): F1.add(pos[T[i]], 1) F2 = FenwickTree(L) ok = False for i in range(K): for a in KA[i]: F1.add(pos[a], -1) F2.add(pos[a-S[i]], 1) for b in KB[i]: j = pos.get(m-b, -1) if j < 0: continue if F1.sum(j, j+1): reta = m-b retb = b elif F2.sum(j, j+1): reta = m-b+S[i] retb = b else: continue ok = True if ok: break for a in KA[i]: F2.add(pos[a-S[i]], -1) F1.add(pos[a], 1) # print(reta, retb) for i in range(N): if reta == T[i]: resi = i+1 break for j in range(M): if retb == B[j]: resj = j+1 break return resi, resj l, r = -1, 10**10 while r-l > 1: m = (l+r)//2 if check(m): l = m else: r = m # print(l, r) ans = calc(r) print(*ans)