#include <iostream>
#include <iomanip>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <sstream>
 
using namespace std;
 
const string TASKNAME = "fraud";
 
int main() {
  freopen((TASKNAME + ".in").c_str(), "r", stdin);
  freopen((TASKNAME + ".out").c_str(), "w", stdout);
  string foo, bar;
  cin >> foo;
  int tt;
  cin >> tt;
  vector <string> ans;
  while (tt--) {
    cin >> bar;
    bool ok = true;
    for (int i = 0; i < 9; i++)
      if (bar[i] != foo[i] && foo[i] != '*') ok = false;
    if (ok) ans.push_back(bar);
  }
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)ans.size(); i++) printf("%s\n", ans[i].c_str());
  return 0;
}