object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val K, Q = sc.nextInt
  val Ds = List.fill(K)(sc.nextLong)
  val NXMs = List.fill(Q)((sc.nextInt, sc.nextInt, sc.nextInt))

  NXMs.foreach{case (n, x, m) =>
    val ds = Ds.map{case d => if (d%m == 0) m else d%m}
    val al = x%m + ((n - 1)/K)*ds.sum + ds.take((n - 1)%K).sum
    val ans = n - 1 - al/m
    println(ans)
  }
}