t = int(input())
while t:
    t -= 1

    def read():
        return list(map(int, input().split()))

    n, m = read()
    a = read()
    x = read()

    try:
        Max = a[0]
        iMax = 0

        kek = [Max]
        iKek = [iMax]

        for i in range(1, len(a)):
            a[i] += a[i-1]
            if a[i] > Max:
                Max = a[i]
                iMax = i
                kek.append(Max)
                iKek.append(iMax)

        ans = ""

        # print(kek)
        # print(iKek)

        for num in x:

            if a[n-1] <= 0 and num > Max:
               ans += "-1 "
               continue

            if a[n-1] <= 0:
                k = 0
            else:
                z = num - Max
                if z <= 0:
                    k = 0
                else:
                    k = z//a[n-1] + (z % a[n-1] > 0)

            it = n*k
            postIt = -1

            Sum = a[n-1]*k

            j = 0

            while Sum < num:
                Sum += kek[j]
                postIt = iKek[j]
                j += 1

            ans += str(it + postIt) + ' '

        print(ans)
    except Exception as pr:
        print(len(kek), j)