#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int K, Q; cin >> K >> Q;
  vector<ll> D(K); rep(i, K) cin >> D[i];
  while (Q--) {
    ll N, X, M; cin >> N >> X >> M;
    X %= M;
    ll s = 0;
    rep(i, K) {
      if (D[i] % M == 0) {
        s += M;
      } else {
        s += D[i] % M;
      }
    }
    ll y = X + s * ((N - 1) / K);
    rep(i, (N - 1) % K) {
      if (D[i] % M == 0) {
        y += M;
      } else {
        y += D[i] % M;
      }
    }
    cout << (N - 1) - y / M << endl;
  }
}