def drive(a, x):
    b = [a[0]]
    for i in range(1, len(a)):
        b.append(a[i] + b[i-1])
    k = b[-1]
    re = []
    n = len(b)
    
    if (k == 0):
        for j in range(len(x)):
            for i in range(n):
                if (x[j] == b[i]):
                    re.append(i)
                    break
            if (len(re) != j+1):
                re.append(-1)
    else:
        for va in x:
            m = 1000000001
            for i in range(n):
                c = (va - b[i]) / k
                if (c == int(c) and c >= 0):
                    m = min(m, n*c+i)
            if (m != 1000000001):
                re.append(int(m))
            else:
                re.append(-1)
    
    return re


t = int(input())
for i in range(t):
    n, m = list(map(int, input().strip().split()))
    a = list(map(int, input().strip().split()))
    x = list(map(int, input().strip().split()))
    
    result = drive(a, x)
    print(' '.join(map(str, result)))