import std;void main(){long k,q,n,x,m,s;readf!"%d %d
"(k,q);long[]D=readln.split.to!(long[])(),S;while(q--){readf!"%d %d %d
"(n,x,m);n--;S=[s=0];foreach(d;D)S~=s+=(d%m?d%m:m);writeln(n-(x%m+n/k*s+S[n%k])/m);}}