import heapq import sys input = sys.stdin.readline def solve(): T = int(input()) for _ in range(T): N, K = 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())) heap = [] # (cost, count) total = 0 gold = 100 # initial for i in range(N): # BUY phase if B[i] > 0: heapq.heappush(heap, (A[i], B[i])) total += B[i] # enforce storage limit K while total > K: cost, cnt = heapq.heappop(heap) if cnt > total - K: heapq.heappush(heap, (cost, cnt - (total - K))) total = K else: total -= cnt # SELL phase sell = D[i] price = C[i] while sell > 0 and heap: cost, cnt = heapq.heappop(heap) take = min(cnt, sell) gold += take * (price - cost) cnt -= take sell -= take total -= take if cnt > 0: heapq.heappush(heap, (cost, cnt)) print(gold - 100) if __name__ == "__main__": solve()