import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val k, q = in.next().toInt
  val d = new Array[Int](k)
  for (i <- 0 until k)
    d(i) = in.next().toInt
  
  //
  val d2 = new Array[Int](k)
  for (_ <- 1 to q) {
    //  n, x, m
    val num, init, mod = in.next().toInt

    for (i <- 0 until k)
      d2(i) = d(i) % mod

    var ans: Long = num-1
    val base = (num-1) / k
    val extra = (num-1) % k // これ未満の j は base+1回足される

    // ==
    for (j <- 0 until k) {
      if (d2(j) == 0) {
        ans -= base
        if (j < extra) ans -= 1
      }
    }

    // >
    var acc: Long = init
    for (j <- 0 until k) {
      acc += d2(j).toLong * base
      if (j < extra) acc += d2(j)
    }
    ans -= acc / mod - init / mod
    
    pw.println(ans)
  }

  pw.flush()
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
