import Control.Monad
import qualified Data.Vector.Unboxed as V

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

count :: (V.Unbox a, Eq a) => a -> V.Vector a -> Int
count a v = V.length $ V.elemIndices a v

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