#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int d,n;
int meslen;
int len;
string mes;
string piece[30];
string now;

int dp[51][51];
bool levenshtein(int m) {
  for (int i=1; i<=m; ++i) {
    int mi = INF;
    for (int j=max(1,i-d); j<=min(meslen,i+d); ++j) {
      if (now[i-1] == mes[j-1]) dp[i][j]=dp[i-1][j-1];
      else {
        dp[i][j] = min(min(dp[i-1][j],  // a deletion
                           dp[i][j-1]), // an insertion
                       dp[i-1][j-1]) + 1; // a substituion
      }
      mi = min(mi, dp[i][j]);
    }
    if (mi > d) return 0;
  }
  return 1;
}

// int dp[50][50][50];
// void calcEditDist() {
// }

bool levenshtein(const string &s, const string &t) {
  int n = s.size();
  int m = t.size();
  REP(i,n) dp[i][0]=i;
  REP(i,m) dp[0][i]=i;
  for (int i=1; i<=n; ++i) {
    for (int j=1; j<=m; ++j) {
      dp[i][j] = min(min(dp[i-1][j] + 1,  // a deletion
                        dp[i][j-1] + 1), // an insertion
                    dp[i-1][j-1] + (s[i-1] != t[j-1])); // a substituion
    }
  }
  return dp[n][m]<=d;
}

vector<pii> next[30][50];
vector<string> nextstr[30][50];

void calcNext() {
  REP(a,n) {
    REP(i,meslen+2) {
      next[a][i].clear();
      nextstr[a][i].clear();
    }
    REP(b,n) {
      for (int i=1; i<=len; ++i) {
        bool ok = 1;
        REP(j,len-i) if (piece[a][i+j]!=piece[b][j]) ok = 0;
        if (ok) {
          string t = piece[a] + piece[b].substr(len-i);
          for (int j=0; j+len+i<=meslen+2; ++j) {
            // bool ok = 0;
            // for (int k=max(0,j-2); k<=j+2&&k+len+i<=meslen+2; ++k) {
            //   if (levenshtein(t,mes.substr(k,len+i))) {
            //     ok = 1;
            //     break;
            //   }
            // }
            // if (ok) {
            //   if (j==0 && b
            //   nextstr[a][j].push_back(piece[b].substr(len-i));
            //   next[a][j].push_back(pii(b,i));              
            // }
            nextstr[a][j].push_back(piece[b].substr(len-i));
            next[a][j].push_back(pii(b,i));
          }
        }
      }
    }
  }
}

vector<string> ans;

ll hs(const string &s) {
  ll res = 0;
  REP(i,s.size()) {
    res = res*1000000009 + s[i];
  }
  return res;
}

map<ll,int> mp[50];

int cnt, cnt1, cnt2;
void dfs(int pos, int id) {
  cnt2++;
  
  // if (mp[pos+len].count(now)) return;
  // mp[pos+len][now] = 1;
  
  if (!levenshtein(pos+len)) return;
  // cout << now << endl;
  if (dp[pos+len][meslen] <= d) {
    ans.push_back(now);
    // cout << now << endl;
  }

  string tmp = now;
  REP(i,next[id][pos].size()) {
    int b = next[id][pos][i].first;
    int p = next[id][pos][i].second;
    if (pos+p+len > meslen+2) continue;
    now = tmp + nextstr[id][pos][i];
    ll hash = hs(now);
    if (mp[pos+p].count(hash)) continue;
    mp[pos+p][hash] = 1;
    // if (!levenshtein(pos+p+len)) continue;
    // if (dp[min(meslen,pos+p+len)][pos+p+len] > d) continue;
    dfs(pos+p, b);
  }
  now = tmp;
}

int main() {
  int N;
  while(scanf("%d%d",&d,&N),d||N) {
    REP(i,50) mp[i].clear();
    cin >> mes;
    meslen = mes.size();
    n = 0;
    REP(i,N) {
      cin >> piece[i];
    }
    sort(piece, piece+N);
    n = unique(piece, piece+N) - piece;
    // REP(i,n) {
    //   cout << piece[i] << endl;
    // }
    // cout << endl;
    len = piece[0].size();
    calcNext();
    ans.clear();
    cnt = 0,cnt1=0,cnt2=0;
    
    REP(i,50) dp[i][0]=dp[0][i]=i;
    for (int i=1; i<=meslen+2; ++i)
      for (int j=1; j<=meslen+2; ++j)
        if (abs(i-j)>d) dp[i][j]=INF;
    REP(j,n) {
      now = piece[j];
      dfs(0,j);
    }
    //printf("%d %d %d\n",cnt,cnt1,cnt2);
    sort(ALL(ans));
    cout << ans.size() << endl;
    if (ans.size() <= 5) {
      REP(i,ans.size()) {
        cout << ans[i] << endl;
      }
    }
  }
}

Measured memory_bytes: 63276