Q=int(input()) for _ in range(Q): N,M=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) D=list(map(int,input().split())) Ga=[[] for i in range(N+M+1)] Gb=[[] for i in range(N+M+1)] result=-1 for i in range(N): x=C[i] Ga[x].append(i) for i in range(M): x=D[i] Gb[x].append(i) va=[0]*(N+1) vb=[0]*(M+1) for i in range(N): va[i]=va[i-1]+A[i] for i in range(M): vb[i]=vb[i-1]+B[i] from bisect import bisect_right for x in range(1,N+M+1): if len(Ga[x])*len(Gb[x])==0: continue d=-1 g=[] h=[] for pos in Ga[x]: if pos=0: s=va[2*d] score=-10**20 for pos in Gb[x]: t=bisect_right(g,pos) if t>0: d=g[t-1] l,r=pos-d,pos+d if 0<=l=N//2: d=N-1-pos g.append(d) h.append(va[N-1]-va[N-1-(2*d+1)]) g=g[::-1] h=h[::-1] score=-10**20 if d>=0: for pos in Gb[x]: t=bisect_right(g,pos) if t>0: d=g[t-1] l,r=pos-d,pos+d if 0<=l=0: s=va[2*d] score=-10**20 for pos in Gb[x]: t=bisect_right(g,pos) if t>0: d=g[t-1] l,r=pos-d,pos+d if 0<=l=N//2: d=N-1-pos g.append(d) h.append(va[N-1]-va[N-1-(2*d+1)]) g=g[::-1] h=h[::-1] score=-10**20 if d>=0: for pos in Gb[x]: t=bisect_right(g,pos) if t>0: d=g[t-1] l,r=pos-d,pos+d if 0<=l