K, Q = list(map(int, input().split()))

D = [int(a) for a in input().split()]

for _ in range(Q):

    N, X, M = list(map(int, input().split()))

    if N <= K + 1:

        A = [0] * N

        A[0] = X % M

        ans = 0

        for i in range(N-1):

            A[i+1] = (A[i] + D[i]) % M

            if A[i+1] > A[i]:

                ans += 1

        print(ans)

        continue

    ans = N - 1

    t = X%M

    for i in range(K):

        d = (D[i]-1) % M + 1

        a = (N-i-2) // K + 1

        t += d * a

    ans -= t // M

    print(ans)
K, Q = list(map(int, input().split()))

D = [int(a) for a in input().split()]

for _ in range(Q):

    N, X, M = list(map(int, input().split()))

    t = X%M

    for i in range(K):

        t += ((D[i]-1) % M + 1) * ((N-i-2) // K + 1)

    print((N - 1 - t//M))
K, Q = list(map(int, input().split()))
D = [int(a) for a in input().split()]
for _ in range(Q):
    N, X, M = list(map(int, input().split()))
    if N <= K + 1:
        A = [0] * N
        A[0] = X % M
        ans = 0
        for i in range(N - 1):
            A[i + 1] = (A[i] + D[i]) % M
            if A[i + 1] > A[i]:
                ans += 1
        print(ans)
        continue
    ans = N - 1
    t = X % M
    for i in range(K):
        d = (D[i] - 1) % M + 1
        a = (N - i - 2) // K + 1
        t += d * a
    ans -= t // M
    print(ans)

K, Q = list(map(int, input().split()))
D = [int(a) for a in input().split()]
for _ in range(Q):
    N, X, M = list(map(int, input().split()))
    t = X % M
    for i in range(K):
        t += ((D[i] - 1) % M + 1) * ((N - i - 2) // K + 1)
    print((N - 1 - t // M))

-    if N <= K + 1: -        A = [0] * N -        A[0] = X % M -        ans = 0 -        for i in range(N - 1): -            A[i + 1] = (A[i] + D[i]) % M -            if A[i + 1] > A[i]: -                ans += 1 -        print(ans) -        continue -    ans = N - 1 -        d = (D[i] - 1) % M + 1 -        a = (N - i - 2) // K + 1 -        t += d * a -    ans -= t // M -    print(ans) +        t += ((D[i] - 1) % M + 1) * ((N - i - 2) // K + 1) +    print((N - 1 - t // M))