import java.io.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Solution for NEERC'2013 Problem F: Fraud Busters.
 * This solution checks correctness of the input.
 *
 * @author Roman Elizarov
 */
public class fraud_re {

    public static void main(String[] args) throws Exception {
        new fraud_re().go();
    }

    void go() throws Exception {
        long time = System.currentTimeMillis();
        read();
        solve();
        write();
        System.out.printf("Done in %d ms%n", System.currentTimeMillis() - time);
    }

    String code;
    int n;
    String[] regs;

    void read() throws Exception {
        Scanner in = new Scanner(new File("fraud.in"));
        code = in.next();
        in.nextLine();
        assert validCode(code, true);
        n = in.nextInt();
        in.nextLine();
        assert n >= 1 && n <= 1000;
        regs = new String[n];
        Set<String> set = new HashSet<>(); // validate different
        for (int i = 0; i < n; i++) {
            regs[i] = in.next();
            in.nextLine();
            assert validCode(regs[i], false);
            assert set.add(regs[i]);
        }
        in.close();
    }

    private boolean validCode(String s, boolean scanned) {
        if (s.length() != 9)
            return false;
        for (int i = 0; i < 9; i++) {
            char c = s.charAt(i);
            if ((c < '0' || c > '9') && (c < 'A' || c > 'Z') && (!scanned || c != '*'))
                return false;
        }
        return true;
    }

    int k;

    void solve() {
        k = 0;
        for (int i = 0; i < n; i++)
            if (match(code, regs[i]))
                k++;
    }

    private boolean match(String code, String reg) {
        for (int i = 0; i < 9; i++) {
            char c = code.charAt(i);
            char d = reg.charAt(i);
            if (c != d && c != '*')
                return false;
        }
        return true;
    }

    void write() throws Exception {
        PrintWriter out = new PrintWriter("fraud.out");
        out.println(k);
        for (int i = 0; i < n; i++)
            if (match(code, regs[i]))
                out.println(regs[i]);
        out.close();
    }

//----------------- just for validation ------------------

    /**
     * Strict scanner to verify 100% correspondence between input files and input file format specification.
     * It is a drop-in replacement for {@link java.util.Scanner} that could be added to a solution source
     * (cut-and-paste) without breaking its ability to work with {@link java.util.Scanner}.
     */
    public class Scanner {
        private final BufferedReader in;
        private String line = "";
        private int pos;
        private int lineNo;

        public Scanner(File source) throws FileNotFoundException {
            in = new BufferedReader(new FileReader(source));
            nextLine();
        }

        public void close() {
            assert line == null : "Extra data at the end of file";
            try {
                in.close();
            } catch (IOException e) {
                throw new AssertionError("Failed to close with " + e);
            }
        }

        public void nextLine() {
            assert line != null : "EOF";
            assert pos == line.length() : "Extra characters on line " + lineNo;
            try {
                line = in.readLine();
            } catch (IOException e) {
                throw new AssertionError("Failed to read line with " + e);
            }
            pos = 0;
            lineNo++;
        }

        public String next() {
            assert line != null : "EOF";
            assert line.length() > 0 : "Empty line " + lineNo;
            if (pos == 0)
                assert line.charAt(0) > ' ' : "Line " + lineNo + " starts with whitespace";
            else {
                assert pos < line.length() : "Line " + lineNo + " is over";
                assert line.charAt(pos) == ' ' : "Wrong whitespace on line " + lineNo;
                pos++;
                assert pos < line.length() : "Line " + lineNo + " is over";
                assert line.charAt(pos) > ' ' : "Line " + lineNo + " has double whitespace";
            }
            StringBuilder sb = new StringBuilder();
            while (pos < line.length() && line.charAt(pos) > ' ')
                sb.append(line.charAt(pos++));
            return sb.toString();
        }

        public int nextInt() {
            String s = next();
            assert s.length() == 1 || s.charAt(0) != '0' : "Extra leading zero in number " + s + " on line " + lineNo;
            assert s.charAt(0) != '+' : "Extra leading '+' in number " + s + " on line " + lineNo;
            try {
                return Integer.parseInt(s);
            } catch (NumberFormatException e) {
                throw new AssertionError("Malformed number " + s + " on line " + lineNo);
            }
        }
    }
}
