object Main extends App {
    val in = io.Source.stdin.getLines
    val Array(n, m) = in.next.split(" ").map(_.toInt)
    val dic = in.take(n).toSeq
    val slates = in.map(_.replaceAll("\\*", ".*").replaceAll("\\?", "."))
    slates.foreach(w => println(dic.count(_.matches(w))))
}