import Control.Applicative ((<$>))
import Control.Monad (replicateM, foldM)
import Data.List (foldl', findIndices, find)

main :: IO ()
main = do
  n <- readLn
  nbd <- getLine
  solve nbd <$> replicateM n getLine >>= print

solve :: String -> [String] -> Int
solve nbd = foldl' f 0
  where f ct obd = case find smdf ixc of
                    Just _ -> ct + 1
                    Nothing -> ct
          where ixs = map (\c -> findIndices (==c) obd) nbd
                ixc = foldM (\xs ys -> do
                                y <- ys
                                return (y:xs)) [] ixs

smdf :: [Int] -> Bool
smdf = all (==0) . (tail >>= zipWith (-)) . (tail >>= zipWith (-))

