t = int(input())
while t > 0:
    n, m = (int(i) for i in input().split())
    a = list(map(int, input().split()))
    i = 1
    while i < n:
        a[i] += a[i - 1]
        i += 1
    x = list(map(int, input().split()))
    answer = []
    for xi in x:
        if xi <= a[0]:
            answer.append(0)
        elif a[n - 1] <= 0:
            step = 0
            while step < n and a[step] < xi:
                step += 1
            answer.append(step if step != n else -1)
        else:
            sum_cycle = a[n - 1]
            cycles = xi // sum_cycle
            cycles_sec = cycles * n - 1
            cycles_num = cycles * sum_cycle
            if cycles_num < xi:
                step = 0
                while step < n and a[step] + cycles_num < xi:
                    step += 1
                answer.append(cycles_sec + step + 1)
            else:
                answer.append(cycles_sec)
    print(*answer, sep=' ')
    t -= 1