import Main.AhoCorasick.Trie.Trie

import scala.collection.immutable.HashMap
import scala.collection.mutable


object Main extends App {
  import scala.io.StdIn._

  val charactors = (('@' to 'Z')).toArray
  val result = mutable.Set[String]()
  var count = 0
  var pieceLen: Int = 0
  solve()
  def enumerate(prev: List[Char], pieces: AhoCorasick, blank: Int, word: List[Char], d: Int): Unit = {
    val currentBlank = if (pieces.isAccepted) 0 else blank
    if (currentBlank >= pieceLen) {return ()}
    word match {
      case Nil if d == 0 =>
        if (pieces.isAccepted) {
          if (result.add(prev.reverse.mkString(""))) {
            count += 1
          }
        }
      case Nil =>
        enumerate(prev, pieces, blank, Nil, d - 1)
        for (c <- charactors) {
          enumerate(c::prev, pieces.next(c), currentBlank + 1, Nil, d - 1)
        }
      case head::tail if d == 0 => enumerate(head::prev, pieces.next(head), currentBlank + 1, tail, d)
      case head::tail =>
        enumerate(head::prev, pieces.next(head), currentBlank + 1, tail, d)
        enumerate(prev, pieces, blank, tail, d - 1)
        for (c <- charactors) {
          enumerate(c::prev, pieces.next(c), currentBlank + 1, tail, d - 1)
          enumerate(c::prev, pieces.next(c), currentBlank + 1, word, d - 1)
        }
    }
  }
  def solve(): Unit = {
    readLine.trim.split(' ').map(_.toInt) match {
      case Array(0, 0) => return ()
      case Array(_, 0) =>
        println(0)
        solve()
      case Array(d, n) => {
        val changed = readLine.trim.replace('.', '@')
        val pieces = Array.fill(n){readLine.trim.replace('.', '@')}
        pieceLen = pieces.head.length
        count = 0
        result.clear()
        val aho = AhoCorasick(pieces)
        enumerate(Nil, aho, 0, changed.toList, d)
        if (count > 5) {
          println(count)
        }else {
          println(count)
          println(result.toSeq.sorted.mkString("\n").replace('@', '.'))
        }
        solve()
      }
    }
  }


  sealed trait AhoCorasick {
    def next(char: Char): AhoCorasick
    def isAccepted: Boolean
    def matches: List[String]
  }
  case class Root(children: Array[Option[Node]], override val matches: List[String]) extends AhoCorasick {
    override def next(char: Char): AhoCorasick = children(char - '@').getOrElse(this)
    override def isAccepted: Boolean = matches.nonEmpty
  }
  case class Node(children: Array[AhoCorasick], override val matches: List[String]) extends AhoCorasick {
    override def next(char: Char): AhoCorasick = children(char - '@')
    override def isAccepted: Boolean = matches.nonEmpty
  }
  object AhoCorasick {
    def apply(words: Seq[String]): AhoCorasick = {
      val trie = Trie(words)
      val root = Root(Array.fill(charactors.length){None}, trie.matches.toList)
      val queue = mutable.Queue[(Trie, Node, AhoCorasick)]()
      for ((c, i) <- trie.children.zipWithIndex) {
        c match {
          case Some(child) =>
            val node = Node(Array.fill(charactors.length){root}, child.matches.toList)
            root.children(i) = Some(node)
            queue.enqueue((child, node, root))
          case None =>
        }
      }
      while (queue.nonEmpty) {
        val (t, r, longest) = queue.dequeue()
        for ((c, i) <- t.children.zipWithIndex) {
          c match {
            case Some(child) =>
              val nextLongest = longest.next((i + '@').toChar)
              val node = Node(Array.fill(charactors.length){root}, child.matches.toList ++ nextLongest.matches)
              r.children(i) = node
              queue.enqueue((child, node, nextLongest))
            case None =>
              val failed = longest.next((i + '@').toChar)
              r.children(i) = failed
          }
        }
      }
      root
    }
    object Trie {
      case class Trie(matches: Option[String], children: Array[Option[Trie]])
      def apply(words: Seq[String]): Trie = {
        makeNode(words.map(s => (s.toList, s)))
      }
      def makeNode(words: Seq[(List[Char], String)]): Trie = {
        var matchWord = None: Option[String]
        val children = Array.fill(charactors.length){None: Option[Trie]}
        for ((head, words) <- words.groupBy(_._1.headOption)) {
          head match {
            case Some(h) => children(h - '@') = Some(makeNode(words.map{case (list, word) => (list.tail, word)}))
            case None => matchWord = Some(words.head._2)
          }
        }
        Trie(matchWord, children)
      }
    }
  }
}

/*

https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Prelim/1170?year=2010
 */
