# 解説放送

# tee, isliceをやめた



def main():

    k, q = list(map(int, input().split()))

    *d, = list(map(int, input().split()))

    for _ in range(q):

        n, x, m = list(map(int, input().split()))

        *g, = [x % m for x in d]

        rep, rest = divmod(n - 1, k)

        last = x + (sum(g) * rep) + sum(g[:rest])

        eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g) if gg == 0)

        ans = (n - 1) - eq - (last // m - x // m)

        print(ans)





if __name__ == '__main__':

    main()

# 解説放送



def solve():

    from itertools import islice, tee



    k, q = map(int, input().split())

    *d, = map(int, input().split())

    for g in tee(d, q):

        n, x, m = map(int, input().split())

        g = map(lambda x: x % m, g)

        g1, g2, g3 = tee(g, 3)

        rep, rest = divmod(n - 1, k)

        last = x + (sum(g1) * rep) + sum(islice(g2, 0, rest))

        eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g3) if gg == 0)

        ans = (n - 1) - eq - (last // m - x // m)

        yield ans





def main():

    print(*solve(), sep='\n')





if __name__ == '__main__':

    main()

# 解説放送
# tee, isliceをやめた
def main():
    k, q = list(map(int, input().split()))
    (*d,) = list(map(int, input().split()))
    for _ in range(q):
        n, x, m = list(map(int, input().split()))
        (*g,) = [x % m for x in d]
        rep, rest = divmod(n - 1, k)
        last = x + (sum(g) * rep) + sum(g[:rest])
        eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g) if gg == 0)
        ans = (n - 1) - eq - (last // m - x // m)
        print(ans)


if __name__ == "__main__":
    main()

# 解説放送
def solve():
    from itertools import islice, tee

    k, q = map(int, input().split())
    (*d,) = map(int, input().split())
    for g in tee(d, q):
        n, x, m = map(int, input().split())
        g = map(lambda x: x % m, g)
        g1, g2, g3 = tee(g, 3)
        rep, rest = divmod(n - 1, k)
        last = x + (sum(g1) * rep) + sum(islice(g2, 0, rest))
        eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g3) if gg == 0)
        ans = (n - 1) - eq - (last // m - x // m)
        yield ans


def main():
    print(*solve(), sep="\n")


if __name__ == "__main__":
    main()

-# tee, isliceをやめた +def solve(): +    from itertools import islice, tee + +    k, q = map(int, input().split()) +    (*d,) = map(int, input().split()) +    for g in tee(d, q): +        n, x, m = map(int, input().split()) +        g = map(lambda x: x % m, g) +        g1, g2, g3 = tee(g, 3) +        rep, rest = divmod(n - 1, k) +        last = x + (sum(g1) * rep) + sum(islice(g2, 0, rest)) +        eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g3) if gg == 0) +        ans = (n - 1) - eq - (last // m - x // m) +        yield ans + + -    k, q = list(map(int, input().split())) -    (*d,) = list(map(int, input().split())) -    for _ in range(q): -        n, x, m = list(map(int, input().split())) -        (*g,) = [x % m for x in d] -        rep, rest = divmod(n - 1, k) -        last = x + (sum(g) * rep) + sum(g[:rest]) -        eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g) if gg == 0) -        ans = (n - 1) - eq - (last // m - x // m) -        print(ans) +    print(*solve(), sep="\n")