import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto K = s[0];
    auto Q = s[1];
    auto D = readln.split.map!(to!long).array;
    auto E = new long[](K);

    while (Q--) {
        s = readln.split.map!(to!int);
        auto N = s[0];
        auto X = s[1].to!long;
        auto M = s[2].to!long;
        X %= M;
        foreach (i; 0..K) E[i] = D[i] % M;
        auto sm = E.sum;
        auto hoge = (1L * (N - 1) / K) * (K - E.count(0)) - (X + sm * ((N - 1) / K)) / M;
        auto fuga = (X + sm * ((N - 1) / K)) % M;
        auto piyo = (N - 1) % K;
        foreach (i; 0..piyo) {
            auto fuga2 = (fuga + E[i]) % M;
            if (fuga2 > fuga) hoge += 1;
            fuga = fuga2;
        }
        hoge.writeln;
    }

}