#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Codeforces Round #702 (Div. 3)

Problem G. Old Floppy Drive

:author:         Kitchen Tong
:mail:    kctong529@gmail.com

Please feel free to contact me if you have any question
regarding the implementation below.
"""

__version__ = '1.2'
__date__ = '2021-03-14'


import sys


def solve(n, m, a, x):
    tmp = 0
    local_max = (-1, 0)
    for i in range(n):
        tmp += a[i]
        if tmp > local_max[1]:
            local_max = (i, tmp)
    cycle = tmp

    ans = list()
    for i in range(m):
        if cycle <= 0 and x[i] > local_max[1]:
            ans.append(-1)
            continue
        if cycle > 0:
            k_cycle = (x[i] - local_max[1]) // cycle
            if (x[i] - local_max[1]) % cycle > 0:
                k_cycle += 1
        else:
            k_cycle = 0
        tmp = k_cycle * cycle
        for j in range(n):
            tmp += a[j]
            if tmp >= x[i]:
                ans.append(k_cycle * n + j)
                break
    return ans


def main(argv=None):
    t = int(input())
    for _ in range(t):
        n, m = map(int, input().split())
        a = list(map(int, input().split()))
        x = list(map(int, input().split()))
        print(' '.join(map(str, solve(n, m, a, x))))
    return 0


if __name__ == "__main__":
    STATUS = main()
    sys.exit(STATUS)
