import java.io.*;
import java.util.*;
 
public class fraud_nn {
 
    static void solve() throws IOException {
        String s = nextToken();
        int n = nextInt();
        String[] ans = new String[n];
        int ac = 0;
        for (int i = 0; i < n; i++) {
            String t = nextToken();
            if (s.length() != t.length()) {
                continue;
            }
             
            boolean ok = true;
            for (int j = 0; j < s.length(); j++) {
                if (s.charAt(j) == '*') continue;
                if (s.charAt(j) != t.charAt(j)) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                ans[ac++] = t;
            }
        }
        out.println(ac);
        for (int i = 0; i < ac; i++) {
            out.println(ans[i]);
        }
    }
 
    public static void main(String[] args) throws Exception {
        File file = new File("fraud.in");
        InputStream input = System.in;
        PrintStream output = System.out;
        if (file.exists() && file.canRead()) {
            input = new FileInputStream(file);
            output = new PrintStream("fraud.out");
        }
        br = new BufferedReader(new InputStreamReader(input));
        out = new PrintWriter(output);
        solve();
        out.close();
    }
 
    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;
 
    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());
    }
 
    static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}