import Control.Monad

main = do
  [k, q] <- map read.words <$> getLine
  d <- map read.words <$> getLine
  nxm <- replicateM q $ map read.words <$> getLine
  mapM_ (print.solve k d) nxm

solve :: Int -> [Int] -> [Int] -> Int
solve k d' [n, x, m] = n - 1 - eqs - gts where
  d = map (`rem` m) d'
  eqs = length (filter (==0) d) * (quot (n-1) k) + length (filter (==0) (take (rem (n-1) k) d))
  gts = quot alast m - quot x m
  alast = foldl (+) x dcnt
  (nq, nr) = quotRem (n-1) k
  cnt i | i < nr = nq + 1
        | otherwise = nq
  dcnt = zipWith (*) d $ map cnt [0..]