struct Scaner<'a> {
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Scaner<'a> {
    fn new(input: &'a str) -> Self {
        Scaner {
            iter: input.split_whitespace(),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug,
    {
        self.iter.next().unwrap().parse().unwrap()
    }
}

fn main() {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    let mut sc = Scaner::new(&input);
    let k: i64 = sc.read();
    let q: i64 = sc.read();
    let d: Vec<i64> = (0..k).map(|_| sc.read()).collect();
    for _ in 0..q {
        let n: i64 = sc.read();
        let x: i64 = sc.read();
        let m: i64 = sc.read();
        let mut a = x % m;
        let mut cnt_eq = 0;
        for i in 0..k {
            let di = d[i as usize] % m;
            let cnt = (n - 2 + k - i) / k;
            if di == 0 {
                cnt_eq += cnt;
            } else {
                a += di * cnt;
            }
        }
        println!("{}", n - 1 - cnt_eq - a / m);
    }
}
