fun main(args: Array<String>) {
    val (K, Q) = readLine()!!.split(" ").map(String::toInt)
    val D = readLine()!!.split(" ").map(String::toInt)
    fun divceil(a: Long, b: Int) = (a + b - 1) / b
    for (i in 1..Q) {
        val (N, X, M) = readLine()!!.split(" ").map(String::toLong)
        var Xn = X
        var eq = 0L
        for (j in 0 until K) {
            val num = divceil(N - j - 1, K)
            Xn += (D[j] % M) * num
            if (D[j] % M == 0L) eq += num
        }
        println((N - 1) - (Xn / M - X / M) - eq)
    }
}