from itertools import product

def another(seq, elem):
    for x in seq:
        if x != elem: return x
    return None

def solve_one():
    e, n = [ int(_) for _ in input().split() ]
    S = [ int(_) for _ in input().split() ]
    V = [ int(_) for _ in input().split() ]

    z = int(input())
    D = [ [ int(_)-1 for _ in input().split() ] for __ in range(z) ]

    k = int(input())
    C = [ [ int(_)-1 for _ in input().split() ] for __ in range(k) ] # -1 lebo interne cislujeme od 0

    q = int(input())
    T = [ int(_) for _ in input().split() ]
    ignore = input()
    U = [ [ int(_)-1 for _ in input().split() ] for __ in range(q) ]

    credit, answer = e, e

    best, best_taken = -1, None
    for taken in product( range(2), repeat=n ):
        ok = True
        
        needs_to_pay = sum( taken[i] * S[i] for i in range(n) )
        if needs_to_pay > e: ok = False
        
        for conflict in C:
            if sum( taken[x] for x in conflict ) > 1: ok = False

        for dependency in D:
            if taken[dependency[0]] and not taken[dependency[1]]: ok = False

        if not ok:
            continue

        curr = e - needs_to_pay + sum( taken[i] * V[i] for i in range(n) )
        for i in range(q):
            if all( taken[u] for u in U[i] ):
                curr += T[i]

        if curr > best: best, best_taken = curr, list(taken)

    print(best)
    #print(*best_taken)

tc = int( input() )
for test in range(tc): solve_one()
