import sys,math,itertools
from collections import Counter,deque,defaultdict
from bisect import bisect_left,bisect_right 
from heapq import heappop,heappush,heapify, nlargest
from copy import deepcopy
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split()))
def inps(): return sys.stdin.readline()
def inpsl(x): tmp = sys.stdin.readline(); return tmp[:x]
def err(x): print(x); exit()

for _ in range(inp()):
    n,m = inpl()
    a = inpl()
    query = inpl()
    acc = list(itertools.accumulate(a))
    las = acc[-1]
    dic = defaultdict(list)
    se = set()
    res = []
    p = {}
    if las == 0:
        for i,x in enumerate(acc):
            if x in se: continue
            dic[x].append(x)
            p[x] = i
        for x in query:
            ans = -1
            if dic[x]: ans = p[x]
            res.append(ans)
    else:
        for i,x in enumerate(acc):
            if x in se: continue
            dic[x%las].append(x)
            p[x] = i
        for x in query:
            ans = -1
            if dic[x%las]:
                dic[x%las].sort()
                ind = bisect_left(dic[x%las],x+1)
                if ind > 0:
                    ans = (x-dic[x%las][ind-1])//las*n+p[dic[x%las][ind-1]]
            res.append(max(ans,-1))
        print(*res)