import sys

from itertools import accumulate





def solve(n, x, m):

    eee = [d % m for d in ddd]

    acc = list(accumulate(eee))

    zero = [int(e == 0) for e in eee]

    zero_acc = list(accumulate(zero))

    loop, rem = divmod(n - 1, k)

    tot = x % m + acc[-1] * loop

    tot_zero = zero_acc[-1] * loop

    if rem > 0:

        tot += acc[rem - 1]

        tot_zero += zero_acc[rem - 1]

    dame = tot // m

    # print(n, x, m)

    # print(eee)

    # print(acc)

    # print(loop, rem)

    # print(tot, dame)

    return n - 1 - dame - tot_zero





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

ddd = list(map(int, input().split()))

buf = []

for line in sys.stdin:

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

    buf.append(solve(n, x, m))

print(('\n'.join(map(str, buf))))

import os

import sys



import numpy as np





def solve(inp):

    k, q = inp[:2]

    ddd = inp[2:k + 2]

    nnn = inp[k + 2::3]

    xxx = inp[k + 3::3]

    mmm = inp[k + 4::3]

    buf = []

    for n, x, m in zip(nnn, xxx, mmm):

        eee = ddd % m

        acc = np.cumsum(eee)

        zero_acc = np.cumsum(eee == 0)

        loop, rem = divmod(n - 1, k)

        tot = x % m + acc[-1] * loop

        tot_zero = zero_acc[-1] * loop

        if rem > 0:

            tot += acc[rem - 1]

            tot_zero += zero_acc[rem - 1]

        dame = tot // m

        buf.append(n - 1 - dame - tot_zero)

    return buf





if sys.argv[-1] == 'ONLINE_JUDGE':

    from numba.pycc import CC



    cc = CC('my_module')

    cc.export('solve', '(i8[:],)')(solve)

    cc.compile()

    exit()



if os.name == 'posix':

    # noinspection PyUnresolvedReferences

    from my_module import solve

else:

    from numba import njit



    solve = njit('(i8[:],)', cache=True)(solve)



inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')

ans = solve(inp)

print(('\n'.join(map(str, ans))))

import sys
from itertools import accumulate


def solve(n, x, m):
    eee = [d % m for d in ddd]
    acc = list(accumulate(eee))
    zero = [int(e == 0) for e in eee]
    zero_acc = list(accumulate(zero))
    loop, rem = divmod(n - 1, k)
    tot = x % m + acc[-1] * loop
    tot_zero = zero_acc[-1] * loop
    if rem > 0:
        tot += acc[rem - 1]
        tot_zero += zero_acc[rem - 1]
    dame = tot // m
    # print(n, x, m)
    # print(eee)
    # print(acc)
    # print(loop, rem)
    # print(tot, dame)
    return n - 1 - dame - tot_zero


k, q = list(map(int, input().split()))
ddd = list(map(int, input().split()))
buf = []
for line in sys.stdin:
    n, x, m = list(map(int, line.split()))
    buf.append(solve(n, x, m))
print(("\n".join(map(str, buf))))

import os
import sys
import numpy as np


def solve(inp):
    k, q = inp[:2]
    ddd = inp[2 : k + 2]
    nnn = inp[k + 2 :: 3]
    xxx = inp[k + 3 :: 3]
    mmm = inp[k + 4 :: 3]
    buf = []
    for n, x, m in zip(nnn, xxx, mmm):
        eee = ddd % m
        acc = np.cumsum(eee)
        zero_acc = np.cumsum(eee == 0)
        loop, rem = divmod(n - 1, k)
        tot = x % m + acc[-1] * loop
        tot_zero = zero_acc[-1] * loop
        if rem > 0:
            tot += acc[rem - 1]
            tot_zero += zero_acc[rem - 1]
        dame = tot // m
        buf.append(n - 1 - dame - tot_zero)
    return buf


if sys.argv[-1] == "ONLINE_JUDGE":
    from numba.pycc import CC

    cc = CC("my_module")
    cc.export("solve", "(i8[:],)")(solve)
    cc.compile()
    exit()
if os.name == "posix":
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit("(i8[:],)", cache=True)(solve)
inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=" ")
ans = solve(inp)
print(("\n".join(map(str, ans))))

+import os -from itertools import accumulate +import numpy as np -def solve(n, x, m): -    eee = [d % m for d in ddd] -    acc = list(accumulate(eee)) -    zero = [int(e == 0) for e in eee] -    zero_acc = list(accumulate(zero)) -    loop, rem = divmod(n - 1, k) -    tot = x % m + acc[-1] * loop -    tot_zero = zero_acc[-1] * loop -    if rem > 0: -        tot += acc[rem - 1] -        tot_zero += zero_acc[rem - 1] -    dame = tot // m -    # print(n, x, m) -    # print(eee) -    # print(acc) -    # print(loop, rem) -    # print(tot, dame) -    return n - 1 - dame - tot_zero +def solve(inp): +    k, q = inp[:2] +    ddd = inp[2 : k + 2] +    nnn = inp[k + 2 :: 3] +    xxx = inp[k + 3 :: 3] +    mmm = inp[k + 4 :: 3] +    buf = [] +    for n, x, m in zip(nnn, xxx, mmm): +        eee = ddd % m +        acc = np.cumsum(eee) +        zero_acc = np.cumsum(eee == 0) +        loop, rem = divmod(n - 1, k) +        tot = x % m + acc[-1] * loop +        tot_zero = zero_acc[-1] * loop +        if rem > 0: +            tot += acc[rem - 1] +            tot_zero += zero_acc[rem - 1] +        dame = tot // m +        buf.append(n - 1 - dame - tot_zero) +    return buf -k, q = list(map(int, input().split())) -ddd = list(map(int, input().split())) -buf = [] -for line in sys.stdin: -    n, x, m = list(map(int, line.split())) -    buf.append(solve(n, x, m)) -print(("\n".join(map(str, buf)))) +if sys.argv[-1] == "ONLINE_JUDGE": +    from numba.pycc import CC + +    cc = CC("my_module") +    cc.export("solve", "(i8[:],)")(solve) +    cc.compile() +    exit() +if os.name == "posix": +    # noinspection PyUnresolvedReferences +    from my_module import solve +else: +    from numba import njit + +    solve = njit("(i8[:],)", cache=True)(solve) +inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=" ") +ans = solve(inp) +print(("\n".join(map(str, ans))))