import sys,collections as cl,bisect as bs

sys.setrecursionlimit(100000)

input = sys.stdin.readline

mod = 10**9+7

Max = sys.maxsize

def l(): #intのlist

    return list(map(int,input().split()))

def m(): #複数文字

    return list(map(int,input().split()))

def onem(): #Nとかの取得

    return int(eval(input()))

def s(x): #圧縮

    a = []

    aa = x[0]

    su = 1

    for i in range(len(x)-1):

        if aa != x[i+1]:

            a.append([aa,su])

            aa = x[i+1]

            su = 1

        else:

            su += 1

    a.append([aa,su])

    return a

def jo(x): #listをスペースごとに分ける

    return " ".join(map(str,x))

def max2(x): #他のときもどうように作成可能

    return max(list(map(max,x)))

def In(x,a): #aがリスト(sorted)

    k = bs.bisect_left(a,x)

    if k != len(a) and a[k] ==  x:

        return True

    else:

        return False

"""

def nibu(x,n,r):

    ll = 0

    rr = r

    while True:

        mid = (ll+rr)//2



    if rr == mid:

        return ll

    if (ここに評価入れる):

        rr = mid

    else:

        ll = mid+1

"""



mod = 10**9+7 #出力の制限

N = 10**5 * 2

def cmb(n, r):

    if ( r<0 or r>n ):

        return 0

    r = min(r, n-r)

    return g1[n] * g2[r] * g2[n-r] % mod

def p(n,r):

    if ( r<0 or r>n ):

        return 0

    return g1[n] * g2[n-r] % mod



g1 = [1, 1] # 元テーブル

g2 = [1, 1] #逆元テーブル

inverse = [0, 1] #逆元テーブル計算用テーブル



for i in range( 2, N + 1 ):

    g1.append( ( g1[-1] * i ) % mod )

    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )

    g2.append( (g2[-1] * inverse[-1]) % mod )

# a = cmb(n,r)



import fractions

from functools import reduce

def gcd(*numbers):

    return reduce(fractions.gcd, numbers)



def gcd_list(numbers):

    return reduce(fractions.gcd, numbers)

def lcm_base(x, y):

    return (x * y) // fractions.gcd(x, y)



def lcm(*numbers):

    return reduce(lcm_base, numbers, 1)



def lcm_list(numbers):

    return reduce(lcm_base, numbers, 1)



k,q = m()



d = l()





for i in range(q):

    n,x,mm = m()

    co = 0



    po = []

    for j in range(k):

        po.append(d[j] % mm if d[j] % mm > 0 else mm)



    """

    for j in range(k):

        if po[j] == 0:

            ccc = ((n-1)//k)

            if (n-1)%k >= j:

                ccc += 1

            co += ccc

    """

    pp = sum(po) * ((n-1)//k)

    pp += x

    for j in range((n-1)%k):

        pp += po[j]

    

    co += (pp//mm) - (x//mm)

    

    print((n-co-1))









import sys,collections as cl,bisect as bs

sys.setrecursionlimit(100000)

input = sys.stdin.readline

mod = 10**9+7

Max = sys.maxsize

def l(): #intのlist

    return list(map(int,input().split()))

def m(): #複数文字

    return list(map(int,input().split()))

def onem(): #Nとかの取得

    return int(eval(input()))

def s(x): #圧縮

    a = []

    aa = x[0]

    su = 1

    for i in range(len(x)-1):

        if aa != x[i+1]:

            a.append([aa,su])

            aa = x[i+1]

            su = 1

        else:

            su += 1

    a.append([aa,su])

    return a

def jo(x): #listをスペースごとに分ける

    return " ".join(map(str,x))

def max2(x): #他のときもどうように作成可能

    return max(list(map(max,x)))

def In(x,a): #aがリスト(sorted)

    k = bs.bisect_left(a,x)

    if k != len(a) and a[k] ==  x:

        return True

    else:

        return False

"""

def nibu(x,n,r):

    ll = 0

    rr = r

    while True:

        mid = (ll+rr)//2



    if rr == mid:

        return ll

    if (ここに評価入れる):

        rr = mid

    else:

        ll = mid+1

"""



mod = 10**9+7 #出力の制限

N = 10**5 * 2

def cmb(n, r):

    if ( r<0 or r>n ):

        return 0

    r = min(r, n-r)

    return g1[n] * g2[r] * g2[n-r] % mod

def p(n,r):

    if ( r<0 or r>n ):

        return 0

    return g1[n] * g2[n-r] % mod



g1 = [1, 1] # 元テーブル

g2 = [1, 1] #逆元テーブル

inverse = [0, 1] #逆元テーブル計算用テーブル



for i in range( 2, N + 1 ):

    g1.append( ( g1[-1] * i ) % mod )

    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )

    g2.append( (g2[-1] * inverse[-1]) % mod )

# a = cmb(n,r)



import fractions

from functools import reduce

def gcd(*numbers):

    return reduce(fractions.gcd, numbers)



def gcd_list(numbers):

    return reduce(fractions.gcd, numbers)

def lcm_base(x, y):

    return (x * y) // fractions.gcd(x, y)



def lcm(*numbers):

    return reduce(lcm_base, numbers, 1)



def lcm_list(numbers):

    return reduce(lcm_base, numbers, 1)



k,q = m()



d = l()





for i in range(q):

    n,x,mm = m()

    co = 0



    po = []

    for j in range(k):

        #po.append(d[j] % mm if d[j] % mm > 0 else mm)

        po.append(d[j] % mm)



    for j in range(k):

        if po[j] == 0:

            ccc = ((n-1)//k)

            if (n-1)%k >= j+1:

                ccc += 1

            co += ccc



    pp = sum(po) * ((n-1)//k)

    pp += x

    for j in range((n-1)%k):

        pp += po[j]

    

    co += (pp//mm) - (x//mm)

    

    print((n-co-1))









import sys, collections as cl, bisect as bs

sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9 + 7
Max = sys.maxsize


def l():  # intのlist
    return list(map(int, input().split()))


def m():  # 複数文字
    return list(map(int, input().split()))


def onem():  # Nとかの取得
    return int(eval(input()))


def s(x):  # 圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x) - 1):
        if aa != x[i + 1]:
            a.append([aa, su])
            aa = x[i + 1]
            su = 1
        else:
            su += 1
    a.append([aa, su])
    return a


def jo(x):  # listをスペースごとに分ける
    return " ".join(map(str, x))


def max2(x):  # 他のときもどうように作成可能
    return max(list(map(max, x)))


def In(x, a):  # aがリスト(sorted)
    k = bs.bisect_left(a, x)
    if k != len(a) and a[k] == x:
        return True
    else:
        return False


"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2
    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
mod = 10**9 + 7  # 出力の制限
N = 10**5 * 2


def cmb(n, r):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


def p(n, r):
    if r < 0 or r > n:
        return 0
    return g1[n] * g2[n - r] % mod


g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)
# a = cmb(n,r)
import fractions
from functools import reduce


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


k, q = m()
d = l()
for i in range(q):
    n, x, mm = m()
    co = 0
    po = []
    for j in range(k):
        po.append(d[j] % mm if d[j] % mm > 0 else mm)
    """
    for j in range(k):
        if po[j] == 0:
            ccc = ((n-1)//k)
            if (n-1)%k >= j:
                ccc += 1
            co += ccc
    """
    pp = sum(po) * ((n - 1) // k)
    pp += x
    for j in range((n - 1) % k):
        pp += po[j]
    co += (pp // mm) - (x // mm)
    print((n - co - 1))

import sys, collections as cl, bisect as bs

sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9 + 7
Max = sys.maxsize


def l():  # intのlist
    return list(map(int, input().split()))


def m():  # 複数文字
    return list(map(int, input().split()))


def onem():  # Nとかの取得
    return int(eval(input()))


def s(x):  # 圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x) - 1):
        if aa != x[i + 1]:
            a.append([aa, su])
            aa = x[i + 1]
            su = 1
        else:
            su += 1
    a.append([aa, su])
    return a


def jo(x):  # listをスペースごとに分ける
    return " ".join(map(str, x))


def max2(x):  # 他のときもどうように作成可能
    return max(list(map(max, x)))


def In(x, a):  # aがリスト(sorted)
    k = bs.bisect_left(a, x)
    if k != len(a) and a[k] == x:
        return True
    else:
        return False


"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2
    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
mod = 10**9 + 7  # 出力の制限
N = 10**5 * 2


def cmb(n, r):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


def p(n, r):
    if r < 0 or r > n:
        return 0
    return g1[n] * g2[n - r] % mod


g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)
# a = cmb(n,r)
import fractions
from functools import reduce


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


k, q = m()
d = l()
for i in range(q):
    n, x, mm = m()
    co = 0
    po = []
    for j in range(k):
        # po.append(d[j] % mm if d[j] % mm > 0 else mm)
        po.append(d[j] % mm)
    for j in range(k):
        if po[j] == 0:
            ccc = (n - 1) // k
            if (n - 1) % k >= j + 1:
                ccc += 1
            co += ccc
    pp = sum(po) * ((n - 1) // k)
    pp += x
    for j in range((n - 1) % k):
        pp += po[j]
    co += (pp // mm) - (x // mm)
    print((n - co - 1))

-        po.append(d[j] % mm if d[j] % mm > 0 else mm) -    """ +        # po.append(d[j] % mm if d[j] % mm > 0 else mm) +        po.append(d[j] % mm) -            ccc = ((n-1)//k) -            if (n-1)%k >= j: +            ccc = (n - 1) // k +            if (n - 1) % k >= j + 1: -    """