import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

long prime = 101;
int D, N, L;
char[] kaizan;
long[] ph;
char[] set = '.'~iota('A', 'Z'+1).map!(a=>a.to!char).array;
bool[char] contain;
void main() {
    while(true) {
        int[] input = readln.split.to!(int[]);
        if (input == [0, 0]) break;
        D = input[0];
        N = input[1];
        kaizan = readln.chomp.to!(char[]);
        ph = new long[N];
        contain = null;
        for(int i=0; i<set.length; i++) {
            contain[set[i]] = false;
        }
        foreach(int i; 0..N) {
            char[] piece = readln.chomp.to!(char[]);
            L = piece.length.to!int;
            for(int j=0; j<L; j++) {
                contain[piece[j]] = true;
                ph[i] += piece[j]*prime^^(L-1-j);
            }
        }
        ph.sort;

        char[][] ans = dfs(0, 0, kaizan, 0, 0, -10, -10, -10).sort.uniq.array;
        ans.length.writeln;
        if (ans.length <= 5) {
            for(int i=0; i<ans.length; i++) {
                ans[i].writeln;
            }
        }
    }
}

char[][] dfs(int depth, int d, char[] str, int flg, long th, int insertedIndex, int replacedIndex, int removedIndex) {
    char[][] result;
    if (depth == str.length) {
        if (d<D) {
            // insert back
            for (int i=0; i<set.length; i++) {
                char[] _str = str[0..depth] ~ set[i] ~ str[depth..$];
                result ~= dfs(depth, d+1, _str, flg, th, depth, replacedIndex, removedIndex);
            }
        }
        if (flg == ~(~0<<L)) result ~= str;
    } else {
        if (d<D) result ~= infect(depth, d, str, flg, th, insertedIndex, replacedIndex, removedIndex);
        flg = (flg<<1) & ~(1<<L);
        th = th*prime + str[depth];
        if (depth>=L) th -= str[depth-L]*prime^^L;
        if (depth>=L-1) flg = flg | rabinKarp(th);
        if (depth<L-1 || flg & 1<<(L-1)) {
            result ~= dfs(depth+1, d, str, flg, th, insertedIndex, replacedIndex, removedIndex);
        }
    }
    return result;
}

char[][] infect(int depth, int d, char[] str, int flg, long th, int insertedIndex, int replacedIndex, int removedIndex) {
    char[][] result;
    // insert
    if (depth!=insertedIndex && depth!=replacedIndex && depth!=removedIndex) {
        for (int i=0; i<set.length; i++) {
            if (!contain[set[i]]) continue;
            if (set[i] == str[depth] && depth<str.length-1 && str[depth]==str[depth+1]) continue;
            char[] _str = str[0..depth] ~ set[i] ~ str[depth..$];
            result ~= dfs(depth, d+1, _str, flg, th, depth, replacedIndex, removedIndex);
        }
    }
    // replace
    if (depth!=insertedIndex && depth!=insertedIndex+1 && depth!=replacedIndex) {
        for (int i=0; i<set.length; i++) {
            if (set[i] == str[depth]) continue;
            if (!contain[set[i]]) continue;
            char[] _str = str.dup;
            _str[depth] = set[i];
            result ~= dfs(depth, d+1, _str, flg, th, insertedIndex, depth, removedIndex);
        }
    }
    // remove
    for (int i=0; i<1; i++) {
        if (depth==insertedIndex) continue;
        if (depth==insertedIndex+1) continue;
        if (depth==replacedIndex) continue;
        if (depth<str.length-2 && str[depth]==str[depth+1] && str[depth+1]==str[depth+2]) continue;
        if (D-d==1 && depth<str.length-1 && str[depth]==str[depth+1]) continue;
        char[] _str = str[0..depth] ~ str[depth+1..$];
        result ~= dfs(depth, d+1, _str, flg, th, insertedIndex, replacedIndex, depth);
    }
    return result;
}

int rabinKarp(long th) {
    int left = 0;
    int right = N-1;
    while (left<=right) {
        int center = (left+right)/2;
        if (ph[center] > th) {
            right = center-1;
        } else if (ph[center] < th) {
            left = center+1;
        } else {
            return ~(~0<<L);
        }
    }
    return 0;
}