N = int(input()) B = [] M = [] C = [] for i in range(N): B.append( list(map(int, input().split(' '))) ) M.append( int(input()) ) C.append( sorted(list(map(int, input().split(' ')))) ) def cut(i,b1,b2): n = 0 bamboo = B[i][b1] while 0 < bamboo: bamboo = bamboo - C[i][n] n = n + 1 n = n - 1 bamboo = B[i][b2] while 0 < bamboo: bamboo = bamboo - C[i][n] n = n + 1 n = n - 1 return n for i in range(N): n1 = cut(i,0,1) n2 = cut(i,1,0) print(max(n1,n2))