import bisect
for _ in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    dp = [0]*n
    check_point = []
    cnt = 0
    for i in range(n):
        if i==0:
            dp[i] = a[i]
        else:
            dp[i] = dp[i-1] + a[i]
        if cnt==0 and dp[i]>0:
            check_point.append((dp[i], i))
            cnt += 1
        elif cnt!=0 and dp[i]>check_point[cnt-1][0]:
            check_point.append((dp[i], i))
            cnt += 1

    for i in range(m):
        ans = -1
        if cnt!= 0:
            if b[i]>check_point[cnt-1][0] and dp[n-1]>0:
                tmp = b[i]
                tmp -= check_point[cnt-1][0]
                if tmp%dp[n-1] == 0:
                    ans = (tmp//dp[n-1])*n + check_point[cnt-1][1]
                else:
                    to_find = b[i] - ((tmp//dp[n-1])+1)*dp[n-1]
                    pos = bisect.bisect_left(check_point, (to_find, 0))
                    ans = (tmp//dp[n-1] + 1)*n + check_point[pos][1]
            elif b[i]>check_point[cnt-1][0]:
                ans = -1
            else:
                pos = bisect.bisect_left(check_point, (b[i], 0))
                ans = check_point[pos][1]
        print(ans, end=' ')
    print()



