import java.io.*;
import java.util.*;
 
public class fraud_keka {
    private static void solve() throws IOException {
        String pat = nextToken();
        int n = nextInt();
        List<String> ans = new ArrayList<>();
        i: for (int i = 0; i < n; i++) {
            String q = nextToken();
            for (int j = 0; j < 9; j++) {
                if (pat.charAt(j) != '*' && pat.charAt(j) != q.charAt(j)) {
                    continue i;
                }
            }
            ans.add(q);
        }
        out.println(ans.size());
        for (String q: ans) {
            out.println(q);
        }
    }
 
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new FileReader("fraud.in"));
        out = new PrintWriter("fraud.out");
        solve();
        out.close();
    }
 
    static BufferedReader br;
    static PrintWriter out;
    static StringTokenizer st;
 
    static String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }
 
    static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
 
    static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
}